0% found this document useful (0 votes)
45 views

hw1 Soln

This homework assignment involves translating between pseudo-instructions, assembly code, and machine code for a MIPS processor. Students are asked to translate pseudo-instructions into equivalent MIPS instructions, assemble MIPS assembly code into machine code, and translate machine code back into MIPS assembly code with labels.

Uploaded by

Bin Phan Van
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

hw1 Soln

This homework assignment involves translating between pseudo-instructions, assembly code, and machine code for a MIPS processor. Students are asked to translate pseudo-instructions into equivalent MIPS instructions, assemble MIPS assembly code into machine code, and translate machine code back into MIPS assembly code with labels.

Uploaded by

Bin Phan Van
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

EE 471 – Computer Design and Organization

HW #1 – Due 1/10
1.) Pseudo-instructions (instructions that are not actually part of the MIPS
instruction set) often appear in MIPS programs. This can be for the
convenience of programmer or to make them more readable by humans.
Translate the following pseudo-instructions into the minimal sequence of
actual MIPS instructions that perform the desired function. You may
need to use the $at register to store a temporary value.

move $t1, $t2 $t1 = $t2


ble $t3, $t5, L if($t3 <= $t5) go to label L
li $t1, 16-bit value $t1 = 16-bit value
addi $t0, $t2, 32-bit value $t0 = $t2 +32-bit value
move $t1, $t2 
add $t1, $t2, $zero

ble $t3, $t5, L 


slt $at, $t5, $t3
beq $at, $zero, L

li $t1, small 
ori $t1, $zero, small
This makes sure that the upper 16-bits of the register are zero. This mirrors what
occurs in a “lui” instruction (upper 16-bits are a constant, lower 16-bits are zero).

addi $t1, $zero, small


This sign-extends the constant. Which we want to do largely depends on what we
will do with the constant after we load it in.

addi $t0, $t2, big 


lui $at, big[31:16]
ori $at, $at, big[15:0]
add $t0, $t2, $at
2.) Convert the following assembly program into machine code:
Assume the program begins at memory location 51210.
Label Assembly Address Instruction
Begin: addi $t0, $zero, 0 512 001000 00000 01000 0000000000000000
addi $t1, $zero, 1 516 001000 00000 01001 0000000000000001
Loop: slt $t2, $a0, $t1 520 000000 00100 01001 01010 00000 101010
bne $t2, $zero, finish 524 000101 01010 00000 0000000000000011
add $t0, $t0, $t1 528 000000 01000 01001 01000 00000 100000
addi $t1, $t1, 2 532 001000 01001 01001 0000000000000010
j loop 536 000010 00000000000000000010000010
finish: add $v0, $t0, $zero 540 000000 01000 00000 00010 00000 100000

3.) Convert the following machine code to assembly (don’t forget to create labels for branch or
jump targets):
Address Instruction Label Assembly
512 000110 01000 00000 0000000000000010 blez $t0, Marker
516 101011 01000 00100 0000000000000000 sw $a0, 0($t0)
520 100011 01000 00100 0000000000000100 lw $a0, 4($t0)
524 001110 00101 01000 0001111101110011 Marker: xori $t0, $a1, 8051
528 000000 00100 00100 00101 00000 100000 add $a1, $a0, $a0

You might also like