1 / 20

Overview

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 x3000 Test x3005 Next x300A

lot
Download Presentation

Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Overview • Projects • The Assembly Process • Programmed I/O • Interrupt Driven I/O

  2. LC-3 Assembly Language Syntax: LABEL OPCODE OPERANDS ;COMMENTS optional mandatory Symbol Table: SymbolAddress Start x3000 Test x3005 Next x300A Number x3010 String x3011

  3. An Assembly Language Program ; ; Program to multiply a number by the constant 6 ; .ORIG x3050 LD R1, SIX LD R2, NUMBER AND R3, R3, #0 ; Clear R3. It will ; contain the product. ; The inner loop ; AGAIN ADD R3, R3, R2 ADD R1, R1, #-1 ; R1 keeps track of BRp AGAIN ; the iteration. ; HALT ; NUMBER .BLKW 1 SIX .FILL x0006 ; .END Symbol Table: Symbol Address AGAIN x3053 NUMBER x3057 SIX x3058

  4. Count the occurrences of a character in a file (1 0f 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 x3000 AND R2, R2, #0 ; R2 is counter, initially 0 LD R3, PTR ; R3 is pointer to character file GETC ; R0 gets input character LDR R1, R3, #0 ; R1 gets first character from file ; ; Test character for end of file ; TEST ADD R4, R1, #-4 ; Test for EOT (ASCII x04) BRz OUTPUT ; If done, prepare the output ; ; Test character for match. If a match, increment count. ; NOT R1, R1 ADD R1, R1, R0 ; If match, R1 = xFFFF NOT R1, R1 ; If match, R1 = x0000 BRnp GETCHAR ; If no match, do not increment ADD R2, R2, #1 ; ; Get next character from file. ; GETCHAR ADD R3, R3, #1 ; Point to next character. LDR R1, R3, #0 ; R1 gets next char to test BRnzp TEST

  5. Count the occurrences of a character in a file (2 of 2). ; ; Output the count. ; OUTPUT LD R0, ASCII ; Load the ASCII template ADD R0, R0, R2 ; Covert binary count to ASCII OUT ; ASCII code in R0 is displayed. HALT ; Halt machine ; ; Storage for pointer and ASCII template ; ASCII .FILL x0030 ; ASCII offset PTR .FILL x4000 ; PTR to character file .END

  6. 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?

  7. More than One Object (Load) File • Symbol Table Symbols Externals Exports Addresses Start x3000 Number x300A Data ? Value ? • The “Linker/Loader” would generate another “global table to resolve • Externals & Exports at Load time

  8. 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.

  9. LC-3 has Memory Mapped I/O LC-3 Memory Layout: x0000 – x00FF Trap vectors x0100 – x2FFF System Programs & Data x3000 – xFDFF User Programs Area xFE00 – xFFFF I/O Programming “Registers”

  10. 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

  11. 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)

  12. Keyboard I/O KBDR: Assigned to xFE02 Data is in KBDR[7:0] Read only Register KBSR: Assigned to xFE00 Status is in KBSR[15] Set to “1” when new data is ready Cleared when data is read

  13. Simple Input from Keyboard START LDI R1, A ; Test for BRzp START ; character input LDI R0, B BRnzp NEXT_TASK ; Go to the next task A .FILL xFE00 ; Address of KBSR B .FILL xFE02 ; Address of KBDR

  14. Monitor I/O DDR: Assigned to xFE06 Data is in DDR[7:0] DSR: Assigned to xFE04 Status is in DSR[15] Set to “1” when data is picked up Cleared when new data is written

  15. Simple Ouput to Monitor START LDI R1, A ; Test to see if BRzp START ; output register is ready STI R0, B BRnzp NEXT_TASK A .FILL xFE04 ; Address of DSR B .FILL xFE06 ; Address of DDR

  16. Echo from Keyboard to Monitor START LDI R1, KBSR ; Test for character input BRzp START LDI R0, KBDR ECHO LDI R1, DSR ; Test output register ready BRzp ECHO STI R0, DDR BRnzp NEXT_TASK KBSR .FILL xFE00 ; Address of KBSR KBDR .FILL xFE02 ; Address of KBDR DSR .FILL xFE04 ; Address of DSR DDR .FILL xFE06 ; Address of DDR

  17. The I/O Routine for the LC-3 Keyboard START ST R1,SaveR1 ; Save registers needed ST R2,SaveR2 ; by this routine ST R3,SaveR3 ; LD R2,Newline L1 LDI R3,DSR BRzp L1 ; Loop until Monitor is ready STI R2,DDR ; Move cursor to new clean line ; LEA R1,Prompt ; Starting address of prompt string Loop LDR R0,R1,#0 ; Write the input prompt BRz Input ; End of prompt string L2 LDI R3,DSR BRzp L2 ; Loop until Monitor is ready STI R0,DDR ; Write next prompt character ADD R1,R1,#1 ; Increment Prompt pointer BRnzp Loop ; Get next prompt character ; Input LDI R3,KBSR BRzp Input ; Poll until a character is typed LDI R0,KBDR ; Load input character into R0 L3 LDI R3,DSR BRzp L3 ; Loop until Monitor is ready STI R0,DDR ; Echo input character ; L4 LDI R3,DSR BRzp L4 ; Loop until Monitor is ready STI R2,DDR ; Move cursor to new clean line LD R1,SaveR1 ; Restore registers LD R2,SaveR2 ; to original values LD R3,SaveR3 BRnzp NEXT_TASK ; Do the program's next task ;

  18. The I/O Routine for the LC-3 Keyboard (2) SaveR1 .BKLW 1 ; Memory for registers saved SaveR2 .BKLW 1 SaveR3 .BKLW 1 DSR .FILL xFE04 DDR .FILL xFE06 KBSR .FILL xFE00 KBDR .FILL xFE02 Newline .FILL x000A ; ASCII code for newline Prompt .STRINGZ "Input a character>"

  19. Keyboard I/O KBDR: Assigned to xFE02 Data is in KBDR[7:0] Read only Register KBSR: Assigned to xFE00 Status is in KBSR[15] Set to “1” when new data is ready Cleared when data is read Interrupt Request is in KBSR[14]

  20. Monitor I/O DDR: Assigned to xFE06 Data is in DDR[7:0] DSR: Assigned to xFE04 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]

More Related