![]() |
Jupyter at Bryn Mawr College |
|
|
Public notebooks: /services/public/dblank / CS240 Computer Organization / 2015-Fall / Notes |
This notebook looks at including memory operations in our machine code programs.
First, some hints from the last homework.
You can use %dump START STOP
to look at contiguous memory locations.
%dump x3000 x300A
If you find that you have weird things in memory, you can perform a %reset
of the LC3:
%reset
%dump x3000 x300A
That looks better!
If you find yourself running an infinite loop, like this:
.ORIG x3000
0000 111 111111111 ; BRnzp go -1
.END
%exe
Press the black square in the toolbar, or select menu -> Kernel -> Interrupt. That should send a Keyboard Interrupt
to the LC3 and stop it from running.
There is no CLR instruction. You can use something like:
0101 001 001 1 00000 ;; AND R0, R0, #0
Using a BR instruction is the only way to have any program control at all. There is no IF, FOR, WHILE, etc. You have to use BR to build such constructs.
.ORIG x3000
0101 000 000 1 00000 ; R0 to 0
0001 000 000 1 01010 ; R0 <- R0
0000 010 000000011 ; BRp go to +3
0001 001 000 0 00 000 ; R1 <- R0
0001 000 000 1 11111 ; R0 - 1
0000 111 111111100 ; BR go to -4
1111 0000 00100101 ; HALT
.END
%exe
%%python
print(bin(16 * 15 + 15))
print(hex(16 * 15 + 15))
You can stick data into memory using the .ORIG directive:
.ORIG x3001
1111111111111111
.END
.ORIG x3000
1111111111111110
.END
LD R4, VALUE ; R4 <- mem[VALUE]
15 - 12 | 11 - 9 | 8 - 0 |
---|---|---|
0010 | DR | PCoffset9 |
LDI R4, VALUE ; R4 <- mem[mem[VALUE]]
15 - 12 | 11 - 9 | 8 - 0 |
---|---|---|
1010 | DR | PCoffset9 |
LDR R4, R1, VALUE ; R4 <- mem[R1 + VALUE]
15 - 12 | 11 - 9 | 8 - 6 | 5 - 0 |
---|---|---|---|
0110 | DR | BaseR | offset6 |
LEA R4, VALUE ; R4 <- address of VALUE
15 - 12 | 11 - 9 | 8 - 0 |
---|---|---|
1110 | DR | PCoffset9 |
%reset
.ORIG x3000
0010 000 000000001 ;; load next next into R0
1111 0000 00100101 ;; HALT
1111 0000 1111 0000
.END
%exe
.ORIG xF0F0
1111 1110 1110 1101
.END
.ORIG x3000
1010 000 000000001 ;; R0 <- mem[mem[]]
1111 0000 00100101 ;; HALT
1111 0000 1111 0000
.END
%exe
.ORIG x3000
1110 000 000000010 ;; LEA R0 <- address of [PC+ + 2]
0110 001 000 000001 ;; LDR R1 <- mem[r0 + 1]
1111 0000 00100101 ;; HALT
1111 0000 1111 0000
0000 0000 0000 1111
.END
%exe
.ORIG x3100
0000 0000 0000 0001
0000 0000 0000 0001
0000 0000 0000 0001
0000 0000 0000 0001
0000 0000 0000 0001
0000 0000 0000 0001
0000 0000 0000 0001
0000 0000 0000 0001
0000 0000 0000 0001
0000 0000 0000 0001
.END