1 / 9

Assembly language

Assembly language. .ORIG x3000 AND R2, R2, #0 ; R2 is a counter initialize to 0 LEA R3, PTR ; PTR is start address of a file Trap x23 ; get input character to R0 input char AGAIN LDR R1, R3, #0 ; get char from a file

unity-beard
Download Presentation

Assembly language

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. Assembly language .ORIG x3000 AND R2, R2, #0 ; R2 is a counter initialize to 0 LEA R3, PTR ; PTR is start address of a file Trap x23 ; get input character to R0 input char AGAIN LDR R1, R3, #0 ; get char from a file ADD R4, R1, #-4 ; check the end of file ‘eot’ = 4 BRz OUTPUT NOT R1, R1 ADD R1, R1, #1 ADD R1, R1, R0 ; file char vs input char BRnp NEXT ADD R2, R2, #1 ; char found increment counter NEXT ADD R3, R3, #1 ; increment pointer in a file BRnzp AGAIN OUTPUT LD R0, ASCII ; ASCII offset ADD R0, R0, R2 ; count in ASCII TRAP x21 ; display count (R0) TRAP x25 ; halt ASCII .FILL x0030 ; ASCII_offset PTR .STRINGZ "Hello world" ; file .END SSST: CS130 F. Hadziomerovic

  2. Assembly format label opcode operands ; comment AGAIN LDR R1, R3, #0 ; get char from a file Pseudo-ops (Assembler Directives) .ORIG x3100 ; (x – hexadecimal, # - decimal) PC = x3100 .FILL #10 ; this location will be filled with decimal 10 .BLKW 11 ; 11 successive locations are reserved .STRINGZ “Hello” ; 5 successive locations are loaded with char string .END ; end of assembly program .EXTERNAL ; cross-reference SSST: CS130 F. Hadziomerovic

  3. How assembler works Two passes: First pass: Make a symbol table .ORIG x3000 AND R2, R2, #0 ; initialize counter R2 to 0 LEA R3, PTR ; PTR is start address of a file Trap x23 ; get input char to R0 AGAIN LDR R1, R3, #0 ; get char from a file ADD R4, R1, #-4 ; check the end of file ‘eot’ = 4 BRz OUTPUT NOT R1, R1 ADD R1, R1, #1 ADD R1, R1, R0 ; file char vs input char BRnp NEXT ADD R2, R2, #1; char found incr counter NEXT ADD R3, R3, #1; increment pointer in a file BRnzp AGAIN OUTPUT LD R0, ASCII ; ASCII offset ADD R0, R0, R2 ; count in ASCII TRAP x21 ; display count (R0) TRAP x25 ; halt ASCII .FILL x0030 ; ASCII_offset PTR .STRINGZ "Hello world" ; file .END Second pass: Translate mnemonic using symbol table x3000 0101 010 010 1 00000 x3001 1110 011 000010000 (x3012 – x3002 = x10) X3002 1111 0000 00100011 X3003 0110 001 011 000000 X3004 0001 100 001 1 11100 X3005 0000 010 000000111 (x300D – x3006 = x07) X3006 1001 001 001 111111 X3007 0001 001 001 1 00001 X3008 0001 001 001 0 00 000 Etc. SSST: CS130 F. Hadziomerovic

  4. .EXTERNAL ; beyond a single assembly program • .ORIG x3000 • AND R2, R2, #0 ; initialize counter R2 to 0 • LD R3, PTR ; PTR is start address of a file • Trap x23 ; get input char to R0 • AGAIN LDR R1, R3, #0 ; get char from a file • ADD R4, R1, #-4 ; check the end of file ‘eot’ = 4 • BRz OUTPUT • NOT R1, R1 • ADD R1, R1, #1 • ADD R1, R1, R0 ; file char vs input char • BRnp NEXT • ADD R2, R2, #1 ; char found incr counter • NEXT ADD R3, R3, #1 ; increment pointer in a file • BRnzp AGAIN • OUTPUT LD R0, ASCII ; ASCII offset • ADD R0, R0, R2 ; count in ASCII • TRAP x21 ; display count (R0) • TRAP x25 ; halt • ASCII .FILL x0030 ; ASCII_offset • .EXTERNAL STARTofFILE • PTR .FILL STARTofFILE • .END • .ORIG x4000 • STARTofFILE .STRINGZ "Hello World" • .FILL x04 • .END Assembler does not know STARTofFILE location and .EXTERNAL tells it that this will be linked later. When linker is called then cross-references (unresolved labels) are filled in from other Symbol Tables. SSST: CS130 F. Hadziomerovic

  5. Memory mapped Input/Output (I/O) x0000 15 14 0 xFE00 KBSR 15 8 7 0 KBDR xFE02 memory 15 14 0 DSR xFE04 15 8 7 0 DDR xFE06 xFDFF xFE00 KBSR[15] = 1; new char in KBDR DSR[15] = 1 ; DDR is ready for new char. I/O registers xFFFF SSST: CS130 F. Hadziomerovic

  6. Address Control KBDR KBSR DSR MAR DDR Memory mapped Input/Output (I/O) architecture bus GateMDR LD.MAR R.W MDR LD.MDR Memory set re set E MIO.EN 2 test test keyboard display 15 14 0 15 14 0 xFE00 KBSR DSR xFE04 KBSR[15] = 1; new char in KBDR DSR[15] = 1 ; DDR is ready for new char. 15 8 7 0 15 8 7 0 KBDR DDR xFE06 xFE02 SSST: CS130 F. Hadziomerovic

  7. I/O service routines ; input service routine START LDI R1, A BRzp START LDI R0, B BRnzp NEXT_TASK A .FILL xFE00 B .FILL xFE02 ; output service routine START LDI R1, A BRzp START STI R0, B BRnzp NEXT_TASK A .FILL xFE04 B .FILL xFE06 15 14 0 xFE00 KBSR 15 8 7 0 KBDR xFE02 15 14 0 DSR xFE04 ;keyboard echo START LDI R1, KBSR BRzp START LDI R0, KBDR ECHO LDI R1, DSR BRzp ECHO STI R0, DDR BRnzp NEXT_TASK KBSR .FILL xFE00 KBDR .FILL xFE02 DSR .FILL xFE04 DDR .FILL xFE06 15 8 7 0 DDR xFE06 KBSR[15] = 1; new char in KBDR DSR[15] = 1 ; DDR is ready for new char. SSST: CS130 F. Hadziomerovic

  8. LC-3 keyboard input routine • Start ST R1, SaveR1 ; save registers • ST R2, SaveR2 • ST R2, SaveR2 • LD R2, Newline • L1 LDI R3, DSR • BRzp L1 ;loop until display ready • RTI R2, DDR ;display newline • LEA R1, Prompt • Loop LDR R0, R1, #0 • BRz Input • L2 LDI R3, DSR • BRzp L2 ;wait for monitor ready • STI R0, DDR ;write next prompr char. • ADD R1, R1, #1 • BRnxp Loop • Input LDI R3, KBSR • BRzp Input ;wait for char • LDI R0, KBDR ;get input char • L3 LDI R3, DSR • BRzp L3 ;wait for monitor • STI R0, DDR ;display char • L4 LDI R3, DSR • BRzp L4 ;wait for monitor • STI R2, DDR ;move cursor to new line • LD R1, SaveR1 • LD R2, SaveR2 • LD R3, Save R3 • BRnzp Next_Task 29. SaveR1 .BLKW 1 30. SaveR3 .BLKW 1 31. DSR .FILL xFE04 32. DDR .FILL xFE06 33. KBSR .FILL xFE00 34. KBDR .FILL xFE02 35. Newline .FILL x000A 36. Prompt .STRINGZ “Input a character>” Critique: Loops L1, L2, L3, L4 wait until display ready. Loop Input waits until char available – gross. For instance 1 char per sec means wait of 1 million instruction executions – waste of computer time. Solution: interrupt: processor is interrupted only when the character is ready. Generally processor is interrupted when peripheral device needs service. SSST: CS130 F. Hadziomerovic

  9. Interrupt PL2 PL1 15 14 13 0 15 14 13 0 xFE00 KBSR DSR xFE04 Other device priorities Priority decision PL of running program Jump to ISR Interrupt line to processor ISR (Interrupt Service Routine) running program Interrupt is tested before every FETCH cycle. If interrupt priority is larger than running program priority Interrupt is granted: 1. PC and PSR are saved on stack and jump is made to interrupt service routine. 2. Interrupt service routine must end up with RTI (Return from Interrupt) instruction which loads PC and PSR back from the stack. interrupt running program RTI Return from ISR SSST: CS130 F. Hadziomerovic

More Related