Professor Shai Simonson -
CSC 304 - Computer Architecture
Assembly Language Using MIPS
Translation and Assemblers
Due: Friday April 1 (Total: 30 points)
Problems (10 points)
0. Type in the following pseudo-instructions to SPIM, and write down the translated MIPS instructions.
.texta. Explain in your own words why and how the translation works.
lw $7, label
la $8, label
b. Write down the Hex representation for each instruction. Explain your answers.
1. Hand assemble the following lines. You can show your answers in Hex.
add $3, $6, $19
lw $8, 4($5)
2. Hand assemble the following lines. You can show your answers in Hex.
and $5, $6, $18
beq $5, $0, br1
lui $20, 0x66aa
br1: lb $9, -8($20)
3. Reverse engineer these hex values into MIPS instructions. Make up label names if needed. Assume code starts at 0x0040 0000. Use this link to look up opcodes if you can't find them in the book's cheat sheet.
0x0040 0000 0x8166 0000
0x0040 0004 0x0068 a020
0x0040 0008 0x0013 a280
0x0040 000c 0x1274 fffc
Last Program (You can write this
program in Java if you prefer) - A One Operand Assembler
(20 points) The goal of this assignment is to write an assembler for the one operand, two address mode assembly language described below. You do not need to check for syntax errors. You do need to generate the machine code. You do not need to write this program in MIPS. Any language of your choice is okay.
The language has 8 instructions: Load, Store, Add, Sub, Bra, Bgtr, Bzr, End. Every instruction has at most one operand which must be a PC-relative address, or an immediate value. Immediate values are base 10 integer numbers preceded by a #, and PC-relative addresses are written as labels. Every instruction is encoded in 16 bits. The first 3 bits of the instruction are for the opcode, the next bit indicates which of the 2 address modes to use (0 for PC-relative and 1 for immediate), and the last 12 bits hold either a two's complement offset for the PC-relative address (i.e. the difference in bytes between that line and the label), or a two's complement immediate value. Labels must be 3 letters followed by a colon. If a label has no instruction following it, then it is assumed to be an empty 16 bits of memory. You may assume that every machine program will be loaded starting at memory location zero. Note that End is encoded by 111000000000000.
You should read in the assembly program line by line until it sees End. Then you should print out the machine language version.
Here are two examples assuming you number the instructions in order from 000 through 111, and 0 indicates PC-relative while 1 indicates immediate address mode:
Load #23 lop: Add #-1
Store abc Store xyz
End Bzr fin