Question: Start the QtSPIM simulator and load the lab2-01.s file into the simulator. Try running the program with both the run command and the step command.
Start the QtSPIM simulator and load the lab2-01.s file into the simulator. Try running the program with both the run command and the step command.
# lab2-01.s
# Evaluate the expression (10 + 9) and print the result.
# Equivalent C statement: printf("%d ", 10 + 9);
# Equivalent Java statement: System.out.println(10+9);
# StudentID: Name: Date:
# There are four parts to this program.
# Evaluate the expression.
# Print the result.
# Print endl.
# Return.
.data
msg1: .ascii "abcda"
endl: .asciiz " "
.text
.globl main
main:
# Evaluate the expression.
# Put the final result in a0 to prepare for the syscall.
li $t0, 10 # Put 10 in a temporary register
li $t1, 9 # Put 9 in a temporary register
add $a0, $t0, $t1 # a0 = t0 + t1
# Print the integer result in a0
li $v0, 1 # Load the system call number
syscall
# Print endl.
la $a0, endl # Load the address of the string
li $v0, 4 # Load the system call number
syscall
# Return to operating system
li $v0, 10 # Load the system call number.
syscall # Return.
.end
1) Where (to which window) is the output data displayed?
2) Write down the address of the first instruction of the program (see the text window)
3) Write down the address of the first data of the program (see the data window)
4) Write down the value of the register $sp just before you start the program.
5) What is the representation of the newline symbol " " in memory (write down the hexadecimal value)?
7. What is the hexadecimal representation in memory of the string "abcd"?
6) Single step the program and write down the memory addresses and hexadecimal codes that represent the instruction sequence corresponding to this line:
la $a0, endl
li $v0, 4
7) Delete the quotation in the declaration of endl. Save the file and then assemble again the file. Run the program. What happens? Describe?
8) Deliberately insert a syntax error. How does QtSPIM help you in locating the source of the errors? Describe below from your limited experience.
9) Change the code in line 25 and 26 to:
li $t0, 0x70000000
li $t1, 0x10000000
10) Save the file and then assemble again the file. Run the program. What happens? Describe?
11) Change the code in the line 27 to:
addu $a0,$t0,$t1
12) Save the file and then assemble again the file. Then set a breakpoint at the instruction after the added instruction. Run the program. What is the value of $a0? Continue to run the program.
13) Insert the following codes in the line 34:
la $a0, endl
sh $t1, 0($a0)
14) Save the file and then assemble again the file. Run the program. What happens? Describe?
15) Remove the codes you inserted in step 14. Change the data description in the line 16 to:
msg1: .ascii "abcdef"
16) Save the file and then assemble again the file. What is the hexadecimal representation in memory of the data in the line 16-17?
Exit from QtSPIM.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
