Readings
- Assembler:
- N2T: Chapter 6 All (slides All)
- N2T: Chapter 4 as needed, mostly contained in Chapter 6
- ARM Reference: ARM Quick Reference
Description and Testing
This is a continuation of Assignment 11. The goal is to add functionality for stack manipulation and user defined variables/arrays.
What to turn in
Upload
ArmToHack.java/.log and
programming23.png to the Moodle dropbox.
ArmToHack Translator (Stack)
Each translated program should start by initializing the
Stack to the appropriate address in
Memory so that the stack behaves as in our earlier setup for ARM. (The user may change that value later, but it should start with the expected value.)
ArmToHack Translator (Basic LDMIB and STMDA)
Add support for basic
LDMIB and
STMDB. To simplify, for now assume that the register list has a single entry:
STMDA Rn!, {R7}
LDMIB Rn!, {R7}
Here are sample test programs. The first writes three registers on the stack, the second reads three values from the stack.
For convenience each program changes the default value of
SP and sets it closer to the the top:
program11.arm (should
see 12,13,11 in cells 20,19,18)
program12.arm (should
see R1=11,R2=12,R3=13)
What should be the value of
SP when the first program is done? the second?
ArmToHack Translator (Full LDMIB and STMDA)
Add support for
LDMIB and
STMDB with multi-entry register list. The ARM user will be expected to list the registers in the same order for related
STMDA and
LDMIB instructions (for example saving and restoring registers for a function call).
STMDA Rn!, {R7, R2, R11}
LDMIB Rn!, {R7, R2, R11}
Here are sample test programs. The first writes three registers on the stack, the second reads three values from the stack.
For convenience each changes the default value of
SP and sets it closer to the top:
program13.arm |
program14.arm
What should be the value of
SP when the first program is done? the second?
ArmToHack Translator (LDR)
Add support for
LDR (
LDR is easier the
STR):
LDR Rd, [Rb, Ri, LSL #2]
LDR Rd, [Rb, #±N]
Here
Rb is the base register and
Ri is the index which may also be a numeric value (i.e. Operand2).
The
LSL will be ignored, since the Hack alignment is on individual cells, not on 4 bytes as ARM.
program15.arm (should see R7=42)
program16.arm (should see R3=42, R4=24, R5=66)
ArmToHack Translator (STR)
Add support for
STR (
STR is harder, see below):
STR Rs, [Rb, Ri, LSL #2]
STR Rs, [Rb, #±N]
For meaning of
Rb,Ri,#±N and for handling
LSL see the section on
LDR.
program17.arm (should see 42 in cell 19)
program18.arm (should see 42, 24, 66 in cells 18,19,20)
You might discover that with
STR on value is always lost, regardless of how the Hack instructions are ordered. To resolve the issue, use the Stack to store one of the values on top (no need to move
SP, just write directly where
SP points to, since this is a temporay value and it is not important what is currently there or what will remain afterwards.
With the Stack and correct order of instrictions, it should be possible to handle
STR.
Defined Variables
Add support for user defined arrays/variables.
numbers DCD 1, +2, -3
value DCD 4
All user defined variables will start immediately after the registers, i.e. from index 16.
Each value will be allocated just one Hack cell. In the above example, the array
numbers will occupy cells
16-18 and the array
value will occupy cell
19.
program19.arm (should see 1..4 in cells 16..19)
program20.arm (should see 1..8 in cells 16..23)
Defined Variables and LDR
Extend the definition of
LDR to include the option of loading the base of an array:
LDR Rd, =array
This will require another lookup table to store the base of each array. In the above example, the base of array
numbers is
16 and the base of array
value is
19.
program21.arm (should see 4,2,-3,1 in cells 16..19)
program22.arm (should see 1,4,5,5,4,5,7 in registers R4..R10)
Final Test (program23)
Convert the following program and execute it on the Computer.
Upload a screenshot named
program23.png of Hardware Simulator / CPU Emulator that shows the contents of the RAM.
program23.arm (should see 1,3,6,10,15,21 in cells 22..27)
The End