$30
CDA 4205 Computer Architecture
Assignment 2: MIPS Instructions and Assembly Language
1. (4 pts) Bits have no inherent meaning. Given the 32-bit pattern:
1010 1101 0001 0000 0000 0000 0000 0010
What does it represent, assuming it is …
a) A 2's complement signed integer?
b) A MIPS instruction?
2. (4 pts) Determine the absolute value of a signed integer. Show the implementation of the following pseudo-instruction using three real instructions:
abs $t1, $t2
3. (16 pts) For each pseudo-instruction in the following table, produce a minimal sequence of actual MIPS instructions to accomplish the same thing. You may use the $at for some of the sequences. In the following table, imm32 refers to a 32-bit constant.
a) move $t1, $t2
b) clear $t5
c) li $t5, imm32
d) addi $t5, $t3, imm32
e) beq $t5, imm32, Label
f) ble $t5, $t3, Label
g) bgt $t5, $t3, Label
h) bge $t5, $t3, Label
4. (8 pts) Translate the following statements into MIPS assembly language. Assume that a, b, c, and d are allocated in $s0, $s1, $s2, and $s3. All values are signed 32-bit integers.
a) if ((a > b) || (b > c)) {d = 1;}
b) if ((a <= b) && (b > c)) {d = 1;}
5. (8 pts) Consider the following fragment of C code:
for (i=0; i<=100; i=i+1) { a[i] = b[i] + c; }
Assume that a and b are arrays of words and the base address of a is in $a0 and the base address of b is in $a1. Register $t0 is associated with variable i and register $s0 with c. Write the code in MIPS.
6. (8 pts) Add comments to the following MIPS code and describe in one sentence what it computes. Assume that $a0 is used for the input and initially contains n, a positive integer. Assume that $v0 is used for the output.
begin: addi $t0, $zero, 0
addi $t1, $zero, 1
loop: slt $t2, $a0, $t1
bne $t2, $zero, finish
add $t0, $t0, $t1
addi $t1, $t1, 2
j loop
finish: add $v0, $t0, $zero
7. (12 pts) The following code fragment processes an array and produces two important values in registers $v0 and $v1. Assume that the array consists of 5000 words indexed 0 through 4999, and its base address is stored in $a0 and its size (5000) in $a1. Describe what this code does. Specifically, what will be returned in $v0 and $v1?
add $a1, $a1, $a1
add $a1, $a1, $a1
add $v0, $zero, $zero
add $t0, $zero, $zero
outer: add $t4, $a0, $t0
lw $t4, 0($t4)
add $t5, $zero, $zero
add $t1, $zero, $zero
inner: add $t3, $a0, $t1
lw $t3, 0($t3)
bne $t3, $t4, skip
addi $t5, $t5, 1
skip: addi $t1, $t1, 4
bne $t1, $a1, inner
slt $t2, $t5, $v0
bne $t2, $zero, next
add $v0, $t5, $zero
add $v1, $t4, $zero
next: addi $t0, $t0, 4
bne $t0, $a1, outer
Submission Requirements
Your solutions must be in a single file with a file name yourname-hw1.
If scanned from hand-written copies, then the writing must be legible, or loss of credits may occur.
Only submissions via the link on Canvas where this description is downloaded are graded. Submissions to any other locations on Canvas will be ignored.
Late submissions are accepted for a maximum of 3 late days with 20% assignment credit off as late penalization. Assignments submitted after 3 late days will not be accepted.