We're going to start by having you download three LC/3 binary files. The first, numbers.bin, is a list of seven numbers.
0101000000000000 ; load at x5000 0000000000000010 ; 2 0000000000011001 ; 25 0000011111011000 ; 2008 0000000011111111 ; 255 1111100000101000 ; -2008 1111111111100111 ; -25 1111111111111110 ; -2
The second, location.bin, gives the location and size of that list of numbers.
0100000000000000 ; load at x4000 0101000000000000 ; x5000 0000000000000111 ; 7
The third and final,
solveit.bin,
is a somewhat faulty program for adding the numbers in the list
and saving the sum in R0
.
0011000000000000 ; load at x3000 0101000000100000 ; R0 <- 0 1010001000000110 ; R1 <- M[x4000] via LDI 1010010000000110 ; R2 <- M[x4001] via LDI 0110011001000000 ; R3 <- M[R1] 0001000000000011 ; R0 <- R0+R3 0001010010111111 ; R2 <- R2-1 0000001111111100 ; If P bit set, go back to R3 <- M[R1] 1111000000100101 ; HALT 0100000000000000 ; x4000 0100000000000001 ; x4001
Note that the first line of these binary files is the location where the bits should be stored. The remaining line is a word to be stored in memory.
The LC-3 simulation won't accept these .bin files because they really are ASCII files. You need to use the program lc3convertn to convert them into binary files.
lc3convert numbers lc3convert location lc3convert solveit
If you use the command ls -l you should see that you now have some .obj files.
There is a graphical simulator called lc3sim-tk which you are welcome to use. I'm going to stick with the command line lc3sim for this handout.
Go ahead and start lc3sim and load in order numbers, location, and solveit,
(lc3sim) file numbers Loaded "numbers.sym" and set PC to x5000 WARNING: No symbols are available. (lc3sim) file location Loaded "location.sym" and set PC to x4000 WARNING: No symbols are available. (lc3sim) file solveit Loaded "solveit.sym" and set PC to x3000 WARNING: No symbols are available.
The order is important because each file load sets the PC
to the beginning of that file.
At this point, start stepping through your problem
one instruction at a time. Pay attention to
the state of the registers and see if they have the right values.
By the way, if you just hit the Enter
, the
last LC-3 simulator instruction will be executed.
(lc3sim) step PC=x3001 IR=x5020 PSR=x0400 (ZERO) R0=x0000 R1=x7FFF R2=x0000 R3=x0000 R4=x0000 R5=x0000 R6=x0000 R7=x0490 x3001 xA206 LDI R1,x3008 (lc3sim) PC=x3002 IR=xA206 PSR=x0200 (POSITIVE) R0=x0000 R1=x5000 R2=x0000 R3=x0000 R4=x0000 R5=x0000 R6=x0000 R7=x0490 x3002 xA406 LDI R2,x3009
Eventually, the program will terminate, but R0
will
contain 14, rather than 255.
You job is fix the program.
There is only one instruction that needs to be added, but adding that
instruction will mess up the offsets stored in two other instructions.