Overview I/O – memory mapped programmed / interrupt driven Traps mechanism & RET Subroutines & JSR & JSRR & RET Interrupt mechanism & RTI.

Slides:



Advertisements
Similar presentations
Computer Science 210 Computer Organization Strings, I/O, and Trap Service Routines.
Advertisements

Chapter 7 Introduction to LC-3 Assembly Language Assembly Language Assembly Process Using the Editor & Simulator for Assembly Language Programming.
Chapter 10 And, Finally.... Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display A Final Collection of ISA-related.
1 System Calls (TRAPS) and Subroutines Patt and Patel Ch. 9.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
LC-3 Assembly Language Programming Examples
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
Chapter 9 Overview Traps mechanism & RET Subroutines & JSR & JSRR & RET Interrupt mechanism & RTI.
S. Barua – CPSC 240 CHAPTER 10 THE STACK Stack - A LIFO (last-in first-out) storage structure. The.
CSS 372 Oct 2 nd - Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture.
Chapter 5 The LC-3 LC-3 Computer Architecture Memory Map
Chapter 6 Programming in Machine Language The LC-3 Simulator
Chapter 9 & 10 Subroutines and Interrupts. JSR Instruction: JSR offset (11 bit) xxxxxxxxxxx [PC ]  R7, JMP Offset Jump to Subroutine at offset.
Chapters 9 & 10 Midterm next Wednesday (11/19) Trap Routines & RET Subroutines (or Functions) & JSR & JSRR & RET The Stack SSP & USP Interrupts RTI.
CSS 372 Oct 2 nd - Lecture 2 Review of CSS 371: Simple Computer Architecture Chapter 3 – Connecting Computer Components with Buses Typical Bus Structure.
Chapter 9 Trap Routines & RET Subroutines (or Functions) & JSR & JSRR & RET.
Overview Projects The Assembly Process Programmed I/O Interrupt Driven I/O.
Chapter 8 Overview Programmed I/O Introduction to Interrupt Driven I/O Project 3.
TCSS 372A Computer Architecture. Getting Started Get acquainted (take pictures) Review Web Page (
Chapter 8 I/O Programming Chapter 9 Trap Service Routines Programmed I/O Interrupts Interrupt Driven I/O Trap Service Routines.
Chapter 9 Trap Routines TRAP number (go to service routine) & RET (return from service routine) Subroutines (or Functions) JSR offset or JSRR rn (go to.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Chapter 8 Overview Programmed I/O Interrupt Driven I/O.
Overview von Neumann Model Components of a Computer Some Computer Organization Models The Computer Bus An Example Organization: The LC-3.
Midterm Wednesday 11/19 Overview: 25% First Midterm material - Number/character representation and conversion, number arithmetic - DeMorgan’s Law, Combinational.
Chapter 10 The Stack l Stack data structure l Interrupt I/O l Arithmetic using a stack.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 8 Input/Output Basic organization Keyboard input Monitor output Interrupts DMA.
Chapter 8 Input/Output l I/O basics l Keyboard input l Monitor output l Interrupt driven I/O l DMA.
Chapter 10 And, Finally... The Stack. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Stacks A LIFO.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 10 The Stack Stack data structure Activation records and function invocation.
Chapter 9 Chapter 9 Subroutines and TRAPs l Privileged Instructions l TRAP Routines l Subroutines.
Chapter 9 TRAP Routines and Subroutines. 9-2 System Calls Certain operations require specialized knowledge and protection: specific knowledge of I/O device.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 10 The Stack Stack data structure Interrupt I/O (again!) Arithmetic using a stack.
Introduction to Computing Systems and Programming The LC-2.
The Stack An Hong 2015 Fall School of Computer Science and Technology Lecture on Introduction to Computing Systems.
Chapter 10 And, Finally... The Stack
Chapter 9 TRAP Routines and Subroutines
Chapter 7 & 9.2 Assembly Language
Computer Science 210 Computer Organization
HKN ECE 220: Fall 2017 Midterm 1 AJ Schroeder, Evan Lissoos, Utsav Kawrani 23rd September, 2017.
Computer Science 210 Computer Organization
COSC121: Computer Systems: LC3 Traps and Subroutines
Chapter 10 And, Finally... The Stack
Chapter 8 Input/Output I/O basics Keyboard input Monitor output
Chapter 9 TRAP Routines and Subroutines
Chapter 10 The Stack.
Arithmetic using a stack
The LC-3 Instruction Set Architecture Data Movement instructions
Computer Science 210 Computer Organization
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
HKN ECE 220: Spring 2018 Midterm 1
Introduction to Computer Engineering
Chapter 9 TRAP Routines and Subroutines
TRAP Routines Subroutines Privileged Instructions
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Chapter 10 And, Finally... The Stack
Chapter 9 TRAP Routines and Subroutines
Chapter 7 Assembly Language
TRAP Routines Privileged Instructions Subroutines
Chapter 9 TRAP Routines and Subroutines
School of Computer Science and Technology
HKN ECE 220: Fall 2018 Midterm 1 Andrew Fortunat, Jeff Chang, Srijan Chakraborty, Kanad Sarkar February 16, 2019.
Chapter 9 TRAP Routines and Subroutines
Chapter 9 TRAP Routines and Subroutines
Midterm 2 Review Chapters 4-16 LC-3
Chapter 9 TRAP Routines and Subroutines
Presentation transcript:

Overview I/O – memory mapped programmed / interrupt driven Traps mechanism & RET Subroutines & JSR & JSRR & RET Interrupt mechanism & RTI

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” xFE00 KBSR (Keyboard Status Register [15 {Ready}, 14 {Intr enable] ) xFE02 KBDR (Keyboard Data Register [7:0{ascii data}] ) xFE04 DSR (Display Status Register) [15{Done}, 14{Intr enable}] ) xFE06 DDR (Display Data Register [7:0{ascii data}]) xFFFE MCR (Machine Control Register) [15{Run latch}] )

Trap Instruction: TRAP x trap vector F0xx [PC ]  R7 Jump to routine at trap vector address Return RET C1C0 [R7]  PC (JMP R7) Trap Routine

Traps 1)Execute TRAP “vector” - Operating System Service Routines 2)Trap Vectors are at memory locations [0000:00FF] 3)Trap Vectors contain addresses of Trap Service Routines 4)(PC) is loaded into R7 5)Address of Trap Service Routine loaded into PC 6)Service Routine Program executed 7)Trap service routine program ends with an RET ( (R7) loaded into PC)

OUT Service Routine - TRAP x21.ORIG x0430 ; System call starting address ST R1, SaveR1 ; R1 will be used to poll the DSR ; hardware ; Write the character TryWrite LDI R1, DSR ; Get status BRzp TryWrite ; Bit 15 on says display is ready WriteIt STI R0, DDR ; Write character ; return from trap Return LD R1, SaveR1 ; Restore registers RET ; Return from trap (JMP R7, actually) DSR.FILL xFE04 ; Address of display status register DDR.FILL xFE06 ; Address of display data register SaveR1.BLKW 1.END

IN Trap service routine - TRAP x23 ; Service Routine for Keyboard Input ;.ORIG x04A0 START ST R1,SaveR1 ; Save the values in the registers ST R2,SaveR2 ; that are used so that they ST R3,SaveR3 ; can be restored before RET ; LD R2,Newline L1 LDI R3,DSR ; Check DDR -- is it free? BRzp L1 STI R2,DDR ; Move cursor to new clean line ; LEA R1,Prompt ; Prompt is starting address ; of prompt string Loop LDR R0,R1,#0 ; Get next prompt character BRz Input ; Check for end of prompt string L2 LDI R3,DSR BRzp L2 STI R0,DDR ; Write next character of ; prompt string ADD R1,R1,#1 ; Increment Prompt pointer BRnzp Loop ; Input LDI R3,KBSR ; Has a character been typed? BRzp Input LDI R0,KBDR ; Load it into R0 L3 LDI R3,DSR BRzp L3 STI R0,DDR ; Echo input character ; to the monitor ; L4 LDI R3,DSR BRzp L4 STI R2,DDR ; Move cursor to new clean line LD R1,SaveR1 ; Service routine done, restore LD R2,SaveR2 ; original values in registers. LD R3,SaveR3 RET ; Return from trap (i.e., JMP R7) ; SaveR1.BLKW 1 SaveR2.BLKW 1 SaveR3.BLKW 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>".END

HALT service routine – TRAP x25.ORIG xFD70 ; Where this routine resides ST R7, SaveR7 ST R1, SaveR1 ; R1: a temp for MC register ST R0, SaveR0 ; R0 is used as working space ; print message that machine is halting LD R0, ASCIINewLine TRAP x21 LEA R0, Message TRAP x22 LD R0, ASCIINewLine TRAP x21 ; ; clear bit 15 at xFFFE to stop the machine ; LDI R1, MCR ; Load MC register into R1 LD R0, MASK ; R0 = x7FFF AND R0, R1, R0 ; Mask to clear the top bit STI R0, MCR ; Store R0 into MC register ; ; return from HALT routine. ; (how can this routine return if the machine is halted above?) ; LD R1, SaveR1 ; Restore registers LD R0, SaveR0 LD R7, SaveR7 RET ; JMP R7, actually ; ; Some constants ; ASCIINewLine.FILL x000A SaveR0.BLKW 1 SaveR1.BLKW 1 SaveR7.BLKW 1 Message.STRINGZ "Halting the machine." MCR.FILL xFFFE ; Address of MCR MASK.FILL x7FFF ; Mask to clear the top bit.END

; puts.asm ; This service routine writes a NULL-terminated string to the console. ; It services the PUTS service call (TRAP x22). ; Inputs: R0 is a pointer to the string to print. ; Context Information: R0, R1, and R3 are saved, and R7 is lost ; in the jump to this routine ;.ORIG x0450 ; Where this ISR resides ST R7, SaveR7 ; Save R7 for later return ST R0, SaveR0 ; Save other registers that ST R1, SaveR1 ; Are needed by this routine ST R3, SaveR3 ; ; ; Loop through each character in the array ; Loop LDR R1, R0, #0 ; Retrieve the character(s) BRz Return ; If it is 0, done L2 LDI R3,DSR BRzp L2 STI R1, DDR ; Write the character ADD R0, R0, #1 ; Increment pointer BRnzp Loop ; Do it all over again ; ; Return from the request for service call Return LD R3, SaveR3 LD R1, SaveR1 LD R0, SaveR0 LD R7, SaveR7 RET ; ; Register locations DSR.FILL xFE04 DDR.FILL xFE06 SaveR0.FILL x0000 SaveR1.FILL x0000 SaveR3.FILL x0000 SaveR7.FILL x0000.END

JSR Instruction: JSR offset (11 bit) xxxxxxxxxxx [PC ]  R7 JMP Jump to subroutine at offset from PC JSRR Instruction JSRR Rb xxx [PC ]  R7 JMP Jump to subroutine at address in Rb Return RET C1C0 [R7]  PC (JMP R7) Subroutines

1)Execute JSR or JSRR - Call Subroutine or Method 2)Location of Subroutine is specified “in” the Instruction 3) (PC) stored in R7 4) Address from JSR or JSRR is loaded into PC Subroutine is executed R0 possibly contains passed parameter (or address) R5 may be used to return error message Ro possibly contains return parameter (or address) 6) Subroutine program ends with an RET ( (R7) loaded into PC) How does this mechanism support recursion?

Trap service routine for character input(subroutines) (1).ORIG x04A0 START ST R7,SaveR7 JSR SaveReg LD R2,Newline JSR WriteChar LEA R1,PROMPT ; Loop LDR R2,R1,#0 ; Get next prompt char BRz Input JSR WriteChar ADD R1,R1,#1 BRnzp Loop ; Input JSR ReadChar ADD R2,R0,#0 ; Move char to R2 for writing JSR WriteChar ; Echo to monitor ; LD R2, Newline JSR WriteChar JSR RestoreReg LD R7,SaveR7 RET ; JMP R7 terminates ; the TRAP routine SaveR7.FILL x0000 Newline.FILL x000A Prompt.STRINGZ "Input a character>" ; WriteChar LDI R3,DSR BRzp WriteChar STI R2,DDR RET ; JMP R7 terminates subroutine DSR.FILL xFE04 DDR.FILL xFE06 ; ReadChar LDI R3,KBSR BRzp ReadChar LDI R0,KBDR RET KBSR.FILL xFE00 KBDR.FILL xFE02 ; SaveReg ST R1,SaveR1 ST R2,SaveR2 ST R3,SaveR3 ST R4,SaveR4 ST R5,SaveR5 ST R6,SaveR6 RET

Trap service routine for character input(subroutines) (2) ; RestoreReg LD R1,SaveR1 LD R2,SaveR2 LD R3,SaveR3 LD R4,SaveR4 LD R5,SaveR5 LD R6,SaveR6 RET ; SaveR1.FILL x0000 SaveR2.FILL x0000 SaveR3.FILL x0000 SaveR4.FILL x0000 SaveR5.FILL x0000 SaveR6.FILL x0000 ;.END

Stack Push: Push ADD R6, R6, #-1 STR R0, R6, #0 Pop: Pop LDR R0, R6, #0 ADD R6, R6, #1 Which way does the stack grow?

Underflow PopLDR1, Empty ADD R2, R6, R1;Compare stack BRzUnderflow; pointer with x4000 LDRR0, R6, #0 ADDR6, R6, #1 ANDR5, R5, #0 RET UnderflowAND R5, R5, #0 ADDR5, R5, #1 RET Empty.FILLxC000; Empty  -x4000

Overflow PushLDR1, Max ADDR2, R6, R1 BRzOverflow ADDR6, R6, #-1 STRR0, R6, #0 ANDR5, R5, #0 RET OverflowANDR5, R5, #0 ADDR5, R5, #1 RET max.FILLxC005; Max  x3FFB

Subroutine for Push & Pop ; Subroutines for carrying out the PUSH and POP functions. This ; program works with a stack consisting of memory locations x3FFF ; (BASE) through x3FFB (MAX). R6 is the stack pointer. ; POP ST R2,Save2 ; are needed by POP. ST R1,Save1 LD R1,BASE ; BASE contains -x3FFF. ADD R1,R1,#-1 ; R1 contains -x4000. ADD R2,R6,R1 ; Compare stack pointer to x4000 BRz fail_exit ; Branch if stack is empty. LDR R0,R6,#0 ; The actual "pop." ADD R6,R6,#1 ; Adjust stack pointer BRnzp success_exit PUSH ST R2,Save2 ; Save registers that ST R1,Save1 ; are needed by PUSH. LD R1,MAX ; MAX contains -x3FFB ADD R2,R6,R1 ; Compare stack pointer to -x3FFB BRz fail_exit ; Branch if stack is full. ADD R6,R6,#-1 ; Adjust stack pointer STR R0,R6,#0 ; The actual "push" success_exit LD R1,Save1 ; Restore original LD R2,Save2 ; register values. AND R5,R5,#0 ; R5 <-- success. RET fail_exit LD R1,Save1 ; Restore original LD R2,Save2 ; register values. AND R5,R5,#0 ADD R5,R5,#1 ; R5 <-- failure. RET BASE.FILL xC001 ; BASE contains -x3FFF. MAX.FILL xC005 Save1.FILL x0000 Save2.FILL x0000.END