Question
ASSEMBLY ASSIGNMENT So we have to use function calls, save each result to the stack so it has the option of being used as an
ASSEMBLY ASSIGNMENT
So we have to use function calls, save each result to the stack so it has the option of being used as an operand for any other function. I can achieve this on my own using only branching, but I am having a really hard time understanding how function call/procedures work in MIPS. This is what I have for the Power function part of the assignment so far:
.data welc: .asciiz "Welcome to the MIPS Calculator Experience: " opChoice: .asciiz "Which operation would you like to execute? (1 for power, 2 for square root, 3 for multiplication): " useMemData: .asciiz " Using data from memory." result: .asciiz " Result: " another: .asciiz " Saved to memory. Would you like to do another calculation? (0 for no, 1 for yes) " #################For Power######################################### base: .asciiz " What is the base of the power?: " exponent: .asciiz " What is the exponent of the power?: " #################For Square Root################################### radicand: .asciiz " What is the radicand of the square root?: " #################For Multiplication################################ firstMult: .asciiz " What is the first multiplicand?: " secondMult: .asciiz " What is the second multiplicand?: " .text main: Loop: li $v0, 4 #loading syscall for printing strings la $a0, welc #loading string as the argument syscall li $v0, 4 la $a0, opChoice syscall #asking and storing the users choice for operations into $s0 li $v0, 5 syscall move $s0, $v0 jal check check: addi $t0, $t0, 1 addi $t1, $t1, 2 addi $t2, $t2, 3 beq $t0, $s0, Power beq $t1, $s0, Sqrt beq $t2, $s0, Multiplication checkReturn: lw $t3, ($sp) move $a0, $t3 jr $ra Power: addi $sp, $sp, -4 #making space on stack pointer for int li, $v0, 4 la $a0, base syscall li $v0, 5 #asking for and storing base to $s1 syscall move $s1, $v0 li $v0, 4 la $a0, exponent syscall li $v0, 5 #asking for and storing exponent to $s2 syscall move $s2, $v0 j Loop1 #looping to multiply the base by itself 'exponent' amount of times Loop1: beq $s2, $ZERO, quit #if exponent = 0, done with power mult $s1, $s1 mflo $s3 #storing the on-going number (only the quotient) subi $s2, $s2, 1 #decrimenting the exponent value j Loop1 #next iteration quit: sw $s3, ($sp) #storing word to stack j checkReturn Sqrt: Multiplication:
I am probably setting this up all wrong, but I am very confused on how to "conditionally jump" in MIPS. Any help about jal and jr outside of reference docs would be appreciated as this is an important homework and an important concept for me to understand.
This week, you will be working to create a calculator with special operations. Each operation should have its own encapsulated function call. You will be implementing 3 unique functions: 1. Power 2. Square Root 3. Multiplication Plus you get bonus points if you add these functions from last week to your program: 4. Bit Shift 5. Bit Isolation Each one of these operations must be encapsulated in its own function. What this means is that your program will call the appropriate function after it has received the command to do so, and the function will return the result of its calculation. Printing the result and saving to memory should exist in the main function, not within any one of the operation specific functions. Prompting for values can be kept within the operation-specific functions. Similar to last week, you must save each result to memory after having made a calculation. However, this week, you must also be able to optionally use the last saved answer as an operand in the next calculation. The last saved data can be retrieved if one (or more) of the numbers entered into your operation are a 0 - this can be seen in the example below. Note, the comments are explanatory and should not show up in your outputs. This week, you will be working to create a calculator with special operations. Each operation should have its own encapsulated function call. You will be implementing 3 unique functions: 1. Power 2. Square Root 3. Multiplication Plus you get bonus points if you add these functions from last week to your program: 4. Bit Shift 5. Bit Isolation Each one of these operations must be encapsulated in its own function. What this means is that your program will call the appropriate function after it has received the command to do so, and the function will return the result of its calculation. Printing the result and saving to memory should exist in the main function, not within any one of the operation specific functions. Prompting for values can be kept within the operation-specific functions. Similar to last week, you must save each result to memory after having made a calculation. However, this week, you must also be able to optionally use the last saved answer as an operand in the next calculation. The last saved data can be retrieved if one (or more) of the numbers entered into your operation are a 0 - this can be seen in the example below. Note, the comments are explanatory and should not show up in your outputsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started