Assignment 5 for CSCI 255 / ECE 109

Due date

This assignment must be submitted as a single .asm file for Assignment 5 of the CSCI 255/ECE 109 section on UNCA moodle by 5:00 PM on Monday, 20 April.

Programming Task

In this assignment you will the LDR and STR instructions to load and store values from a stack-like memory structure.

Like in Assignment 4, your program should be loaded at address x3400. Your program will "receive" a single argument, an address stored in R5. Your program will use LDR instructions to read four values stored at offsets from R5. If your program changes R5, it must restore it before returning!

Here are the offsets as they will be used in this assignment.

logical name R5 offset
char 4
type 5
base 6
value 7

The char variable is an ASCII character of a hexadecimal digit. The type variable has been set from char using the encoding from Assignment 2. The restriction of char to hexadecimal means that type will be from 0 to 3. The base variable will be one of 8, 10, or 16. It is the base that is to be used in interpretting char. Finally, value corresponds to a partially processed number.

For example, suppose a program is reading the octal number 0763 and has already processed the first two characters. In this case, char would be 51 (ASCII for '3'), base would be 8, and value would be 62 (corresponding to octal 076).

The program computes the result of sticking char to the end of value. In this case that would be 62*8 + 51 - 48. The reason for 48 is because it is the ASCII representation of '0'.

Once the result is computed if should be stored in memory at offset 3 from R5. (See Chapter 14 if you want to know why that location is chosen.)

If char is a decimal digit; then type will not be three, and the result can computed as value*base + char - 48.

If type is 3, then base must be 16. In this case, use the formula, value*16 + (char&0xFFDF) - 55. The reason for 55 is that it is 10 less than 65, the ASCII encoding for 'A'.

Your solution to this assignment should be about half the size as your solution to Assignment 4. (Mine has 31 lines of LC-3 instructions and pseudo-ops.)

Test program

You can use the LC-3 program TestAssign5.asm to test your code.