The program handin33 will only submit files in the cs33/labs/04 directory. (You can run update33 first to set up the directory first.)
You are encouraged to work with a partner; however, you may work alone if you choose to do so.
In this lab, you will write machine language and assembly language programs for the LC-3, convert them to object code for the LC-3 (lc3convert for machine language programs, lc3as for assembly language programs), 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.
(machine language example) ; Store in R3 the value of -R2 (negative R2) 1001 011 010 111111 ; NOT R3, R2 (or R3 = NOT R2) 0001 011 0111 00001 ; R3 = R3 + #1 (assembly language example) ;; Shift R3 to the left two places ADD R3, R3, R3 ADD 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, all programs should begin at x3000 and, unless otherwise specified, should not make any assumptions about the initial state of registers or memory locations.
Write a program called countOnes.bin which counts the number of bits that are set to 1 in memory location x2FFE and stores the result in memory location x2FFF. You will have to manually set the value in memory location x2FFE before your program begins.
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:
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.
Extra challenging (optional): In a file called dec2hex.asm, change your previous program so that it converts decimal input into hexadecimal output. (It's not trivial, but it's not as hard as it seems at first... my implementation took 57 instructions including some data.)