Docsity

MIPS Assembly Homework 4: Machine-Level Representation - Prof. William D. Mcquain, Assignments of Computer Science

Toggle sidebar
bg1
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
1. [30 points] The conditional branch instruction in line #9 is translated to the following native instructions and machine
code:
-------------------------------------------------------
Address Machine code Native MIPS Instruction
-------------------------------------------------------
[0x00400010] [0x0128082a] slt $1, $9, $8 # 9a
[0x00400014] [0x1020000a] beq $1, $0, 10 # 9b
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 MIPS32
Instruction Set, which is available from the course website.
2. [15 points] The unconditional branch instruction in line #14 is translated to the following native instruction and
machine code:
-------------------------------------------------------
Address Machine code Native MIPS Instruction
-------------------------------------------------------
[0x00400038] [0x0401fff6] bgez $0, -10 # 14
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.
pf2

Partial preview of the text

Download MIPS Assembly Homework 4: Machine-Level Representation - Prof. William D. Mcquain and more Assignments Computer Science in PDF only on Docsity!

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

  1. [30 points] The conditional branch instruction in line #9 is translated to the following native instructions and machine code: ------------------------------------------------------- Address Machine code Native MIPS Instruction ------------------------------------------------------- [0x00400010] [0x0128082a] slt $1, $9, $8 # 9a [0x00400014] [0x1020000a] beq $1, $0, 10 # 9b

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.

  1. [15 points] The unconditional branch instruction in line #14 is translated to the following native instruction and machine code: ------------------------------------------------------- Address Machine code Native MIPS Instruction ------------------------------------------------------- [0x00400038] [0x0401fff6] bgez $0, -10 # 14

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

  1. [15 points] If the unconditional branch instruction in line #14 is replaced by the jump instruction

j loop

that will be translated to the following native instruction and machine code:


Address Machine code Native MIPS Instruction

[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.

  1. [15 points] In question 3 the I-format machine code given for the assembly instruction bgez $0, -10 decomposes into the fields: 000001 00000 00001 1111111111110110

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.

  1. [13 points] What decimal (base-10) integer does the following 32-bit two’s complement binary integer represent?

1011 0000 1100 1001 1111 0001 0001 1010

  1. [12 points] What is the 32-bit two's complement representation of the number 79,743ten?