Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this exercise, write the MIPS32 assembly language code that implements print

ID: 3677631 • Letter: F

Question

For this exercise, write the MIPS32 assembly language code that implements print(). The implementation requires 6 instructions: two addi, one jr, one move, and two syscall. Note, you are not being asked to write a complete program; just implement print()

(10 pts) Consider function print0 documented below in pseudocode in the function's header comment block. # FUNCTION: void print (string msg, int n) # DESCRIPTION # Displays a message string (msg contains the address of the string to be printed) using SysPrintStr(). Then # displays the value of int variable n using SysPrintIntO. # PARAMETERS # $a0 msg (addr of string to be displayed) # $a1 n (value of n) # PSEUDOCODE # function print (string msg, int n) returns nothing SysPrintStr (meg #SysPrintInt (n) # end function # RETURNS # Nothing # STACK FRAME # print() is a leaf procedure and does not allocate any local variables, we *could* allocate params msg and n # in print() 's stack frame, but instead, we will optimize the code and not do that.

Explanation / Answer

#Use of 2 addi, one jr, one move, and two syscall

#----------------------------------

.text

.global main

print:

#initialize register

li $a1, 4 #integer variable

la $a0, msg #string message

addi $a1, $a1, -4 #add immidate the negative value to variable

syscell

li $a1, 1 #again assign another variable

move $a1, $v1 # save the return value in $v1

addi $a1, $a1, 4

syscell

jr $ra # jumped to adder stored in $ra

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote