

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CS 2504 Intro Computer Organization Homework 4: Machine-level Representation
Last modified: 9/20/2006 1:34 PM 1
Prepare your answers to the following questions in a plain text file. Submit your file to the Curator system by the posted deadline for this assignment. No late submissions will be accepted.
You will submit your answers to the Curator System (www.cs.vt.edu/curator) under the heading HW4.
For questions 1 through 3, consider the following MIPS assembly program. The addresses shown at the left are correct. However, the assembler has replaced some pseudo-instructions with sequences of native instructions (which are not listed below). Thus, the addresses shown are not sequential. Feel free to examine the code in MARS if you like. Note: "explain carefully" means that you are expected to provide a clear, concise, complete explanation.
.data # 1 [0x10010000] source: .word 42, 17, 23, 93, 46, 79, 88, 30 # 2 [0x10010020] target: .space 32 # 3 [0x10010040] size: .word 8 # 4
.text # 5 [0x00400000] main: move $s0, $zero # 6 [0x00400004] lw $t0, size # 7 [0x0040000c] move $t1, $zero # 8
[0x00400010] loop: ble $t0, $t1, done # 9 [0x00400018] lw $s1, source($s0) # 10 [0x00400024] sw $s1, target($s0) # 11 [0x00400030] addi $t1, $t1, 1 # 12 [0x00400034] addi $s0, $s0, 4 # 13 [0x00400038] b loop # 14 [0x0040003c] done: li $v0, 10 # 15 [0x00400044] syscall # 16
The translation shown above correctly achieves the effect of the original version in the program.
a) What does the instruction shown in line #9a contribute to the execution?
b) Explain carefully why the literal value shown in line #9b is equal to 10.
c) Explain the machine code representation of the instruction shown in line #9b.
Hint: it might be very useful to consult the manual MIPS32 Architecture for Programmers Volume II: The MIPS Instruction Set , which is available from the course website.
Explain carefully why the literal value shown in the native instruction above should be equal to -10. Don't worry about explaining the content of the machine instruction.
CS 2504 Intro Computer Organization Homework 4: Machine-level Representation
Last modified: 9/20/2006 1:34 PM 2
j loop
that will be translated to the following native instruction and machine code:
[0x00400038] [0x08100004] j 4194320 # 14
Explain carefully why the literal value shown in the native instruction above is correct. Note: none of the instruction addresses shown in the original code will change as a result of this modification to the program.
The op and rt fields specify the bgez instruction; the rs field specifies the register to be tested. The interesting field is the final one, which specifies the offset to be used if the branch operation is performed. Explain carefully why the binary value shown above for the offset field is correct.
1011 0000 1100 1001 1111 0001 0001 1010