Question: Computing Logarithm with Recursion This problem focuses on writing a recursive function in assembly in order to practice correctly preserving the architectural state of the
Computing Logarithm with Recursion
This problem focuses on writing a recursive function in assembly in order to practice correctly preserving the architectural state of the system when calling procedures. As with previous assignments, in order for your solution to be graded, it must work with my MUnit tests.
Follow these rules:
Give your procedures the exact names indicated in this write up
Your procedures must be declared globl.
The method parameters will be placed in registers a a and a
The method return value must be placed in register v
Each method must end with the instruction jr $ra
Use the literal value for true and for false.
The Help menu in MARS has a list of instructions, or you may find it helpful to find a set on Google, such as this MIPS instruction reference. MIPS Conventions
This problem will be impossible to do if you do not understand how to use functions and the stack. paying careful attention to the table of preserved and nonpreserved registers. Remember, no registers are preserved automatically you have to be the one to store them! In particular, be sure to use the $s and $t registers correctly. Problem: we often work with powers of two. To answer a question such as "how many bits do I need to represent registers?", we need to be able to take a basetwo logarithm. Because we know that log You can find various reviews of how logarithms work online if you need a refresher, but understanding them will not be strictly necessary to complete this task.
For this assignment, you are going to implement a recursive version of logx Because we work primarily with integers your function will return logx rounded down to the next integer. For example, log but your function will return logtwo Implement logtwoint x The formula for logtwoxrounded down is
logtwox logtwox
where the division is also rounded down to the next integer. We also know that
logtwo
Write a recursive function named logtwo to implement this formula. Note: You must implement the function using this recursive formula. If your logtwo function does not call logtwo inside itself, you have implemented an iterative solution. There should be no loops in your code.
logx is defined only for positive x For invalid agruments ie arguments less than one return
Recall that when we want to multiply or divide by powers of two, we do not actually call mult or div. Instead, we implement this using shifts.
Here is a test class import org.junit.; import static edu.gvsu.mipsunit.munit.MUnit.Register.; import static edu.gvsu.mipsunit.munit.MUnit.; public class LogTwoTest @Before public void before setv; Test logtwo @Test public void logtwoone runlogtwo", ; Assert.assertEquals getv; @Test public void logtwozero runlogtwo", ; Assert.assertEquals getv; Write many more tests! Test Edge Cases end class to use as a starting point for your MUnit tests. Make sure to add more test cases! logtwo.asm?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
