Overview Projects The Assembly Process Programmed IO Interrupt
Overview • Projects • The Assembly Process • Programmed I/O • Interrupt Driven I/O
LC-3 Assembly Language Syntax: LABEL OPCODE OPERANDS ; COMMENTS optional mandatory Symbol Table: Symbol Address Start x 3000 Test x 3005 Next x 300 A Number x 3010 String x 3011
An Assembly Language Program ; ; Program to multiply a number by the constant 6 ; . ORIG x 3050 LD R 1, SIX LD R 2, NUMBER AND R 3, #0 ; Clear R 3. It will ; contain the product. ; The inner loop ; AGAIN ADD R 3, R 2 ADD R 1, #-1 ; R 1 keeps track of BRp AGAIN ; the iteration. ; HALT ; NUMBER. BLKW 1 SIX. FILL x 0006 ; . END Symbol Table: Symbol Address AGAIN x 3053 NUMBER x 3057 SIX x 3058
Count the occurrences of a character in a file (1 0 f 2). ; ; ; ; ; Program to count occurrences of a character in a file. Character to be input from the keyboard. Result to be displayed on the monitor. Program only works if no more than 9 occurrences are found. Initialization. ORIG AND LD GETC LDR x 3000 R 2, #0 ; R 2 is counter, initially 0 R 3, PTR ; R 3 is pointer to character file ; R 0 gets input character R 1, R 3, #0 ; R 1 gets first character from file ; ; Test character for end of file ; TEST ADD R 4, R 1, #-4 ; Test for EOT (ASCII x 04) BRz OUTPUT ; If done, prepare the output ; ; Test character for match. If a match, increment count. ; NOT R 1, R 1 ADD R 1, R 0 ; If match, R 1 = x. FFFF NOT R 1, R 1 ; If match, R 1 = x 0000 BRnp GETCHAR ; If no match, do not increment ADD R 2, #1 ; ; Get next character from file. ; GETCHAR ADD R 3, #1 ; Point to next character. LDR R 1, R 3, #0 ; R 1 gets next char to test BRnzp TEST
Count the occurrences of a character in a file (2 of 2). ; ; Output the count. ; OUTPUT LD R 0, ASCII ; Load the ASCII template ADD R 0, R 2 ; Covert binary count to ASCII OUT ; ASCII code in R 0 is displayed. HALT ; Halt machine ; ; Storage for pointer and ASCII template ; ASCII. FILL x 0030 ; ASCII offset PTR. FILL x 4000 ; PTR to character file. END
One Pass vs Two Pass Assemblers • Two Pass – Checks for syntax errors and builds the Symbol Table during first pass, resolves operand addresses during second pass. • One Pass – Checks for syntax errors, builds the Symbol Table, and resolves operand addresses during the first pass. So why have a two pass?
More than One Object (Load) File • Symbol Table Symbols Start Number Externals Exports Data Value • Addresses x 3000 x 300 A ? ? The “Linker/Loader” would generate another “global table to resolve Externals & Exports at Load time
Input / Output Memory Mapped I/O – A section of the memory address space is reserved for I/O Registers rather than general memory locations. Think of it as “pseudo” memory. The same instructions are used for general programming and I/O programming. Non-Memory Mapped I/O – There is a separate address space for I/O programming, and an entirely separate set of I/O Instructions.
LC-3 has Memory Mapped I/O LC-3 Memory Layout: x 0000 – x 00 FF Trap vectors x 0100 – x 2 FFF System Programs & Data x 3000 – x. FDFF User Programs Area x. FE 00 – x. FFFF I/O Programming “Registers”
Synchronous vs Asynchronous I/O Synchronous – data could be expected to be available when the program wanted it – like data in memory. This is not realistic for I/O Asynchronous – computer is generally much faster than I/O so program must wait until data is available or data has been taken. “Handshaking” is used to ensure that data is available or I/O device is ready
Polling vs Interrrupt Driven I/O Polling – program checks handshaking signals to find when data is available of device is done (typically a loop in the program) Interrupt – program initiates I/O and waits until data is available (typically goes to sleep until the operating system wakes the program up)
Keyboard I/O KBDR: Assigned to x. FE 02 Data is in KBSR: KBDR[7: 0] Read only Register Assigned to x. FE 00 Status is in KBSR[15] Set to “ 1” when new data is ready Cleared when data is read
Simple Input from Keyboard START LDI R 1, A ; Test for BRzp START ; character input LDI R 0, B BRnzp NEXT_TASK ; Go to the next task A . FILL x. FE 00 ; Address of KBSR B . FILL x. FE 02 ; Address of KBDR
Monitor I/O DDR: Assigned to x. FE 06 Data is in DDR[7: 0] DSR: Assigned to x. FE 04 Status is in DSR[15] Set to “ 1” when data is picked up Cleared when new data is written
Simple Ouput to Monitor START LDI R 1, A ; Test to see if BRzp START ; output register is ready STI R 0, B BRnzp NEXT_TASK A . FILL x. FE 04 ; Address of DSR B . FILL x. FE 06 ; Address of DDR
Echo from Keyboard to Monitor START LDI ECHO R 1, KBSR BRzp START LDI R 0, KBDR LDI R 1, DSR BRzp ECHO STI R 0, DDR ; Test for character input ; Test output register ready BRnzp NEXT_TASK KBSR . FILL x. FE 00 ; Address of KBSR KBDR . FILL x. FE 02 ; Address of KBDR DSR . FILL x. FE 04 ; Address of DSR DDR . FILL x. FE 06 ; Address of DDR
The I/O Routine for the LC-3 Keyboard START ST R 1, Save. R 1 ; Save registers needed ST R 2, Save. R 2 ; by this routine ST R 3, Save. R 3 LD R 2, Newline ; L 1 LDI R 3, DSR BRzp L 1 ; Loop until Monitor is ready STI R 2, DDR ; Move cursor to new clean line LEA R 1, Prompt ; Starting address of prompt string ; Loop L 2 LDR R 0, R 1, #0 ; Write the input prompt BRz Input ; End of prompt string LDI R 3, DSR BRzp L 2 ; Loop until Monitor is ready STI R 0, DDR ; Write next prompt character ADD R 1, #1 ; Increment Prompt pointer BRnzp Loop ; Get next prompt character LDI R 3, KBSR BRzp Input ; Poll until a character is typed LDI R 0, KBDR ; Load input character into R 0 LDI R 3, DSR BRzp L 3 ; Loop until Monitor is ready STI R 0, DDR ; Echo input character ; Input L 3 ; L 4 ; LDI R 3, DSR BRzp L 4 ; Loop until Monitor is ready STI R 2, DDR ; Move cursor to new clean line LD R 1, Save. R 1 ; Restore registers LD R 2, Save. R 2 ; to original values LD R 3, Save. R 3 BRnzp NEXT_TASK ; Do the program's next task
The I/O Routine for the LC-3 Keyboard (2) Save. R 1 . BKLW 1 Save. R 2 . BKLW 1 Save. R 3 . BKLW 1 DSR . FILL x. FE 04 DDR . FILL x. FE 06 KBSR . FILL x. FE 00 KBDR . FILL x. FE 02 Newline. FILL x 000 A Prompt ; Memory for registers saved ; ASCII code for newline . STRINGZ "Input a character>"
Keyboard I/O KBDR: Assigned to x. FE 02 Data is in KBSR: KBDR[7: 0] Read only Register Assigned to x. FE 00 Status is in KBSR[15] Set to “ 1” when new data is ready Cleared when data is read Interrupt Request is in KBSR[14]
Monitor I/O DDR: Assigned to x. FE 06 Data is in DDR[7: 0] DSR: Assigned to x. FE 04 Status is in DSR[15] Set to “ 1” when data is picked up Cleared when new data is written Interrupt Request is in DRS[14]
- Slides: 20