Professor Shai
Simonson - CS304 - Computer
Architecture
Assignment 5
Assembly Language Using MIPS
Translation and Assemblers
Due Monday, November 19. (40 points)
label:
lw $7, label
la $8, label
1. Hand assemble the folowing lines
assuming instructions start at 0x0000 4400.
add $3, $6, $19
sb$3, 0($5)
lw $8, 4($5)
2. Hand assemble the folowing lines assuming instructions start at 0x0008 8800.
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.
Address
Contents
0x0040 0000 0x8161
0000
0x0040 0004 0x0068
a020
0x0040 0008 0x0083
a004
0x0040 000c 0x0681
fffd
Last Program (You can write this program in
C++
or Java if you prefer) - A One Operand Assembler
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.
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 preceeded 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.
Examples:
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:
abc:
xyz:
Load
#23
lop: Add #-1
Store
abc
Store xyz
End
Bzr fin
Bra lop
fin: End
http://www.stonehill.edu/compsci/shai.htm