![]() |
Jupyter at Bryn Mawr College |
|
|
Public notebooks: /services/public/dblank / CS240 Computer Organization / 2017-Fall / Notebooks |
.ORIG x3000
.BLKW 1 ; simple variable (or .FILL 0)
.FILL x1234 ; simple initialized variable
.BLKW 10 ; array of ten ints (initialized to 0)
.FILL xFFFF ; simple initialized variable
.END
%dump x3000 x300C
.ORIG x3100
.STRINGZ "abcdefg"
.END
%dump x3100 x310A
.ORIG x3100
.STRINGZ "012345"
.STRINGZ "678"
.END
%dump x3100 x310A
TRAP instructions are called "service calls" because they "call" a service of the Operating System. Generally, thay are composed of:
Opcode | 0000 | Trapvector |
---|---|---|
1111 | 0000 | 0000 0000 |
The Trapvector is 8 bits that indicate a location in memory. Of course the LC-3 has 16 bit addresses, but we only specify 8 here.
%dump x0000
.ORIG x3200
1111 0000 0010 0011
1111 0000 0010 0101
.END
%pc x3200
%cont
.ORIG x3200
1111 0000 0010 0011
1111 0000 0010 0001
1111 0000 0010 0101
.END
%exe
Detailed description on page 543.
Q1:
.ORIG x3000
1110 000 000000010 ;; Put address of "Hello, World!" in R0
1111 0000 0010 0010 ;; PUTS
1111 0000 0010 0101 ;; HALT
.STRINGZ "Hello, world!" ;; DATA
.END
%exe
Q2:
.ORIG x3100
1111 0000 0010 0000 ;; GETC
0001 000 000 1 00001 ;; ADD
1111 0000 0010 0001 ;; OUT
1111 0000 0010 0101 ;; HALT
.END
%exe
Q3:
.ORIG x3100
1111 0000 0010 0000 ;; GETC into R0
0101 001 001 1 00000 ;; put 0 in R1
0001 001 001 1 1 0000 ;; put x30 in R1; ADD
0001 001 001 1 1 0000 ;; put x30 in R1; ADD
0001 001 001 1 1 0000 ;; put x30 in R1; ADD
0001 010 001 1 00000 ;; put x30 in R2; ADD R2 <= R1 + 0
1001 001 001 111111 ;; NOT R1
0001 001 001 1 00001 ;; ADD 1
0001 000 001 0 00 000 ;; ADD -30; R0 <= R1 + 0
;; 1111 0000 0010 0001 ;; OUT
1111 0000 0010 0101 ;; HALT
.END
%pc x3100
%step
%step
%bp x3102
%cont
%regs
%step