Create a simple assembly language program in SPIM. This program should include c
ID: 639681 • Letter: C
Question
Create a simple assembly language program in SPIM. This program should include comments and be properly formatted. It should exit without crashing. The program should implement the following statements (assumed to be from a high-level language):
val1=8;
val2=5;
x=x+3;
y-=1;
x=x+val1;
y+=val2;
x=x=y;
In this example, x and y correspond to $s0 and $s1, respectively. Val1 and val2 should be located in the data part of the program.
A) Trace through your file instruction-by-instruction. What are the values of $s0 after each instruction?
B) What is the final value of x?
C) One instruction in your program will by addi $s0, $s0, 3. Work out, by hand, what you think the hex representation of the statement will be (show the values of each field). Compare this to what is in your SPIM simulator. Are they the same or different?
D) Paste the contents of your assembly language file here:
Explanation / Answer
## SPIM program
main:
1. lw $t0, val1 #load contents of RAM location into ragister $t0: $t0=val1
2. lw $t1, val2 #load contents of RAM location into ragister $t1: $t1=val1
3. addi $s0, $s0, 3 # add immediate $s0 = $s0 + 3 (no sub immediate )
4. li $t2, 1 # load immediate $t2 = 1
5. sub $s1, $s1, $t2 # $s1 = $s1 - $t2 (y-=1)
6. add $s0, $s0, $t0 # $s0 = $s0 + $t0 (x=x+val1)
7. add $s1, $s1, $t1 # $s1 = $s1 + $t1 (y+=val2)
8. move $s0, $s1 # move the content of $s0 to $s1 i.e. x=y
9. move $s0, $s0 # move the content of $s0 to $s0 i.e. x=x
#end
(A). Value of $s0 after each instruction (If we consider $s0 as register $0 then its value will remain as 0 (Zero ) as $0 is hard wired to 0 and can’t be changed ). I have considered $s0 is another temporary register .
(B). Final value of X= 4 (If we consider $s0 as register $0 then its value will remain as 0 (Zero ) as $0 is hard wired to 0 and can’t be changed ).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.