Chapter 9 Overview 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.
Overview I/O – memory mapped programmed / interrupt driven Traps mechanism & RET Subroutines & JSR & JSRR & RET Interrupt mechanism & RTI.
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.
Introduction to LC-3 Assembly Language
S. Barua – CPSC 240 CHAPTER 8 I/O How are I/O devices identified? Memory-mapped vs. special instructions.
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.
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.
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 8 I/O. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-2 I/O: Connecting to Outside World So far,
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
Chapter 9 Chapter 9 Subroutines and TRAPs l Privileged Instructions l TRAP Routines l Subroutines.
Introduction to Computer Engineering CS/ECE 252, Spring 2010 Prof. Guri Sohi Computer Sciences Department University of Wisconsin – Madison.
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 and Programming The LC-2.
Computer Science 210 Computer Organization Machine Language Instructions: Control.
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 8 Input/Output I/O basics Keyboard input Monitor output
Chapter 9 TRAP Routines and Subroutines
Chapter 5 The LC-3.
The LC-3 Instruction Set Architecture Data Movement instructions
LC-3 Details and Examples
Chapter 7 LC-2 Assembly Language.
Computer Science 210 Computer Organization
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
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
Chapter 8 I/O.
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Chapter 9 TRAP Routines and Subroutines
Chapter 7 Assembly Language
TRAP Routines Privileged Instructions Subroutines
Chapter 9 TRAP Routines and Subroutines
Chapter 8 I/O.
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:

Chapter 9 Overview 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 (Supports Software Interrupts) x0020 [x0400] GETC (Read Char from Keyboard) x0021 [x0430] OUT (Write Character to Console) x0022 [x0450] PUTS (Write string to Console) x0023 [x04A0] IN (Prompt, input character from Keyboard, echo character to Console) x0024 [x04E0] PUTSP (Write “packed” string to Console) x0025 [xFD70] HALT (Turn off run latch in MCR) x0100 – x01FF Interrupt Vectors (Supports Hardware Interrupts) x0200 – x2FFF System Programs & Data (“Operating System”) x3000 – xFDFF User Programs Area xFE00 – xFFFF I/O Programming “Registers” (Mapped I/O Registers) xFE00 KBSR [15 {Ready}, 14 {Intr enable}] (Keyboard Status Register) xFE02 KBDR [7:0{ascii data}] (Keyboard Data Register) xFE04 DSR [15{Done}, 14{Intr enable}] (Display Status Register) xFE06 DDR [7:0{ascii data}] (Display Data Register xFFFE MCR [15{Run latch}] (Machine Control Register)

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 stored in 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)

TRAP x21 OUT Trap Vector Routine (Output Character) ; out.asm ;.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

TRAP x23 IN Trap Service Routine (Input Character) ; 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

TRAP x25 HALT Service Routine.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

TRAP 22 PUTS Trap Service Routine (Output a Character String) ; 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

Programming Exercise #1 Write a program to add the contents of R0 and R1, and indicate in R2 if there was an overflow

Programming Exercise #1 ; Add R3=R0+R1, R2=0 indicates no overflow ;.ORIG x3000 AND R2, R2, #0;Initially R2=0 (no Overflow assumed) ADD R3, R0, R1;R3=R0+R1 ; test for overflow ADD R0, R0, #0;test R0 BRN NEG;Branch if RO negative ADD R1, R1, #0;test R1 BRN DONE;No overflow if operand signs differ (R1 NEG) ADD R3, R3, #0 ;maybe, test R3 BRZP DONE ;No overflow if result sign matches (All POS) ADD R2, R2, #1;R2=1 indicating overflow NEG ADD R1, R1, #0;test R1 BRZP DONE;No overflow if operand signs differ (R1 POS) ADD R3, R3, #0;maybe, test R3 BRN DONE;No overflow if result sign matches (All NEG) ADD R2, R2, #1 ;R2=1 indicating overflow DONE HALT.END

Programming Exercise #2 Write a program to count the 1’s in register R0

Programming Exercise #2 ; Program to count 1's in Register R0 ; R3 is a working copy of R0 ; R1 contains the count ; R2 is a loop counter.origx3100 ADD R3, R0, #0;copy R0 into R3 AND R1, R1, #0;clear count ADD R3, R3, #0;test for Neg BRZP NEXT;count if Neg ADD R1, R1, #1 NEXTAND R2, R2, #0 ;check remaining 15 bits ADD R2, R2, #-15 LOOPADD R3, R3, R3;shift R3 left BRZP AGAIN;count if Neg ADD R1, R1, #1 AGAINADD R2, R2, #1;loop until done BRN LOOP HALT.END

Programming Exercise #3 Write a program to add two, two digit numbers read from the console

Programming Exercise #3 ; Program to add two 2 digit decimal numbers read from the console ; R1 & R2 are working registers to load 2 digit number ; R3 is first number ; R4 is second number ; R5 is the sum ; R6 is conversion offset.orig x3600 LEA R0, MESSAGE ;print message PUTS ; Get first number LD R0, NEWLINE ;print PROMPT1 OUT LEA R0, PROMPT1 PUTS GETC ;get first character OUT LD R6, M30 ;convert char to hex ADD R0, R0, R6 ADD R1, R0, R0 ;R1 = 2xR0 ADD R2, R1, #0 ;copy R1 into R2 ADD R2, R2, R2 ;R2 = 4xR0 ADD R2, R2, R2 ;R2 = 8xR0 ADD R2, R2, R1 ;R2 = 10xR0 GETC ;get second character OUT ADD R0, R0, R6 ;convert to hex ADD R3, R2, R0 ;R3 = first decimal number ; Get second number LEA R0, PROMPT2 ;get first character PUTS GETC OUT ADD R0, R0, R6 ;convert char to hex ADD R1, R0, R0 ;R1 = 2xR0 ADD R2, R1, #0 ;copy R1 into R2 ADD R2, R2, R2 ;R2 = 4xR0 ADD R2, R2, R2 ;R2 = 8xR0 ADD R2, R2, R1 ;R2 = 10xR0 GETC ;get second character OUT ADD R0, R0, R6 ;convert to hex ADD R4, R2, R0 ;R4 = first decimal number

Programming Exercise #3 (2) ; Add the numbers and print results ADD R5, R4, R3 ;R5 = R3 + R4 LEA R0, SUM ;prepare to print results PUTS LD R4, P100 ;find 1st digit LD R3, M100 AND R0, R0, #0 LOOP1 ADD R0, R0, #1 ADD R5, R5, R3 ;subtract 100 until negative BRZP LOOP1 ADD R5, R5, R4 ADD R0, R0, #-1 LD R6, P30 ;convert to ascii & print ADD R0, R0, R6 OUT AND R0, R0, #0 ;find 2nd digit LOOP2 ADD R0, R0, #1 ADD R5, R5, #-10 ;subtract 10 until negative BRZP LOOP2 ADD R5, R5, #10 ADD R0, R0, #-1 LD R6, P30 ;convert to ascii & print ADD R0, R0, R6 OUT ADD R0, R5, R6 ;convert and print 3rd digit OUT LD R0, NEWLINE OUT HALT MESSAGE.STRINGZ "Enter two 2-digit decimal numbers:" NEWLINE.FILL x000A PROMPT1.STRINGZ " The sum of " PROMPT2.STRINGZ " and " SUM.STRINGZ " is " M30.FILL xFFD0 ;-x30 P30.FILL X0030 ; x30 M100.FILL xFF9C ;-100 P100.FILL x0064 ; 100.END