Gettysburg College

CS 221
Computer Organization and Assembly Language Programming

Spring 2023

Assignment 12

Due: Thu, May 4, by 11:59pm

Readings

Description and Testing

This is a continuation of Assignment 11. The goal is to add functionality for stack manipulation and user defined variables/arrays.

Separate Files

Organize the code into separate files:

Here is an example:

Student.h | Student.cpp | main.cpp

ArmToHack Translator (Stack)

Each translated program should initialize the Stack to the first address of Video memory.

The user may later alter that value, but the initial value should be as specified above. (For example, the VisUAL IDE always starts with SP=0xFF000000 although we sometimes switched it to 0x1100).

ArmToHack Translator (Basic LDMIA and STMDB)

Add support for basic LDMIA and STRDB. To simplify, for now assume that the register list has a single entry:

STMDB Rn!, {R7}
LDMIA 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 changes the default value of SP and sets it closer to the the top. What should be the value of SP when the first program is done? the second?

program11.arm (should see 12,13,11 in cells 19,18,17)

program12.arm (should see R1=11,R2=12,R3=13)

ArmToHack Translator (Full LDMIA and STMDB)

Add support for LDMIA and STRDB with multi-entry register list. The ARM user will be expected to list the registers in the same order for related STMDB and LDMIA instructions (for example saving and restoring registers for a function call).

STMDB Rn!, {R7, R2, R11}
LDMIA 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 the top. What should be the value of SP when the first program is done? the second?

program13.arm | program14.arm

ArmToHack Translator (LDR and STR)

Add support for LDR and STR:

STR Rs, [Rb, Ri]
LDR Rd, [Rb, Ri]

Here Rb is the base register and Ri is the index which may also be a numeric value (i.e. Operand2).

program15.arm (should see R7=42)

program16.arm (should see R3=42, R4=24, R5=66)

program17.arm (should see 42 in cell 19)

program18.arm (should see 42, 24, 66 in cells 18,19,20)

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 cells 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

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)


What to turn in

Upload ArmToHack.h, ArmToHack.cpp, main.cpp, program23.png to the Moodle dropbox.