code : .data n: .word 13 .text main: add $t0, $0, $zero addi $t1, $zero, 1 la $t
ID: 3801685 • Letter: C
Question
code : .data
n: .word 13
.text
main: add $t0, $0, $zero
addi $t1, $zero, 1
la $t3, n
lw $t3, 0($t3)
fib: beq $t3, $0, finish
add $t2,$t1,$t0
move $t0, $t1
move $t1, $t2
subi $t3, $t3, 1
j fib
finish: addi $a0, $t0, 0
li $v0, 1 # you will be asked about what the purpose of this line for syscall
syscall
li $v0, 10
syscall
Load fib s into MARS and assemble the code. Note that Fibonacci number calculation is as follows: fib[1] 1 Q1. What do the data, word, .text directives mean (i.e., what do you put in each section)? Q2. How do you set a breakpoint in MARS? Set breakpoint on line 15, give the command in your answer. Q3. After your program stops because of a breakpoint, how do you continue to execute your code? How do you step through your code? Q4. How can you find out the contents of a register? How do you modify the value of a register? Q5. At what address is n stored in memory? Calculate the 13th fib number by modifying this memory location Q6. ine 18 and 20 use syscall instruction. What is it and how do you use it?Explanation / Answer
The data segment consists of declarations
A single declaration consists of:
an integer requires 1 word (32 bits) of storage hence we used .word as type for our data value 13.
.word - defines a type. It is used to store 32-bit data in memory
.text- Tells assembler we're in the text segment
code is placed in section of text identified with assembler directive .text
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.