What is the equivalent assembly program for the following that the assembler ass
ID: 3680836 • Letter: W
Question
What is the equivalent assembly program for the following that the assembler assembles after macro expansion. [2 pts]
#<------------------ MACRO DEFINITIONS ---------------------->#
# Macro : print_str
# Usage: print_str()
.macro print_str($arg)
li $v0, 4
# System call code for print_str la $a0, $arg
# Address of the string to print syscall
# Print the string .end_macro
# Macro : exit
# Usage: exit
.macro exit
li $v0, 10 syscall
.end_macro
# Macro: read_int
# Usage: read_int()
.macro read_int($arg)
li $v0,5
# Read intger
syscall
move $arg, $v0
# move the data to target reg .end_macro
# Macro: push
# Usage: push ()
.macro push($reg)
sw $reg, 0x0($sp) # M[$sp] = R[reg]
addi $sp, $sp, -4 # R[sp] = R[sp] - 4
.end_macro
#<------------------ PROG DEFINITIONS ----------------------->#
.text
.globl main
main: print_str msg1
read_int($s0)
beqz $s0, fib_end # Push the first base 0
add $s1, $zero, $zero
push($s1)
addi $s0, $s0, -1
beqz $s0, fib_end # Push the second base 1
addi $s2, $zero, 1
push($s2)
$s0, $s0, -1
fib_loop: beqz $s0, fib_end
add $s3, $s2, $s1
push($s3)
move $s1, $s2
move $s2, $s3
addi $s0, $s0, -1
j fib_loop
fib_end:
exit
#<------------------ DATA DEFINITIONS -----------------------># .data msg1: .asciiz "How many Fibonacci to generate? “
Explanation / Answer
.macro print_str($arg) li $v0, 4 #System call code for print_str la $a0, $arg #Address of the string to print syscall # print the string .end_macro #macro : print_int #usage : rint_int() .macro print_int($arg) li $v0, 1 # system call code for print_int li $a0, $arg # integer to print syscall # print the integer .end_macro .macro read_int($reg) li $v0, 5 #system call code to read_int syscall move $reg, $v0 .end_macro .macro print_reg_int($reg) li $v0, 1 move $a0, $reg syscall .end_macro .macro swap_hi_lo($temp1, $temp2) mtlo $a0 mflo $temp1 mthi $a0 mfhi $temp2 .macro print_hi_lo($strHi, $strEqual, $strComma, $strLo) li $v0, 4 la $a0, $strHi #Address of the string to print syscall li $v0, 4 la $a0, $strEqual #Address of the string to print syscall li $v0, 4 la $a0, $strComma #Address of the string to print syscall .macro exit li $v0, 10 syscall .end_macroRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.