The program handin33 will only submit files in the cs33/lab/04 directory. (You should run update33 first to set up the directory and create any necessary files.)
You are encouraged to work with a partner; however, you may work alone if you choose to do so.
In this lab, we will write machine language programs for the LC-3 in binary (in your favorite text editor), convert them to object code for the LC-3 (lc3convert), and then run them in the LC-3 simulator (lc3sim-tk).
Your programs must follow these following guidelines:
0101 010 011 0 00 101 ; AND R2, R3, R5 (or R2 = R3 AND R5) 0000 011 000000011 ; BRzp #3WARNING: One of the hardest errors to figure out occurs when you change the comment without changing the code. For example, in the BRzp line above, changing BRzp to BRp in the comment does not change your program... you need to also change the binary code. Always verify your program with what the simulator believes you have typed in to be sure you don't get caught by this nasty problem.
; Store in R3 the value of R2 * #-1 1001 011 010 111111 ; NOT R3, R2 (or R3 = NOT R2) 0001 011 011 1 00001 ; R3 = R3 + #1 ; Shift R3 to the left two places 0001 011 011 0 00 011 ; R3 = R3 + R3 0001 011 011 0 00 011 ; R3 = R3 + R3
1111 0000 0010 0101 ; TRAP x25 (or HALT) ; Data 0000 0000 1111 1111 ; Bit mask for low order bits 1111 0111 0011 0001 ; The value xF731
For this lab assignment, you will write a few LC-3 machine-language programs. All programs should begin at x3000 and, unless otherwise specified, you should not make any assumptions about the initial state of registers or memory locations.
Your solution should use a loop to count the bits -- don't just list the same sequence of instructions 16 times to accomplish this task. Challenge: Can you complete this program in 8 instructions or less -- including the HALT instruction?
For example, here the user enters the decimal value "4304" which yields the binary result "0001000011010000".
Input a character> 4 Input a character> 3 Input a character> 0 Input a character> 4 Input a character> 0001000011010000
To avoid complicating issues, you should assume that the user always enters input from keyboard that consists only of the digits 0 through 9 and Enter -- there's no need to do any error checking. Also, you should assume -- again, don't error check -- that all values are positive, and that the user will not type a value larger than (215 - 1) = 32767.
Though this might sound quite complicated, if you break the problem into two halves, it's quite manageable. In the first half, you need to read digits from the keyboard and store these digits as a single number in a register. You don't have to actually convert it to binary -- simply by storing the "appropriate value" in the register, you're storing it in binary! In the second half, you need to print the contents of that register to the screen.
This program is obviously more complicated than the countOnes program, but my fairly straightforward implementation (not doing anything fancy) took 40 instructions including some data. That's not to say your solution won't take more or less: it's just a ballpark number to give you some idea of the complexity of the problem.