Computer Science 210 Computer Organization

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.
Introduction to Computer Engineering ECE 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin –
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.
Chapter 9 TRAP Routines and Subroutines. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 Subroutines.
S. Barua – CPSC 240 CHAPTER 5 THE LC-3 Topics Memory organization Registers Instruction set Opcodes.
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.
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 TRAP Routines and Subroutines. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 System Calls.
S. Barua – CPSC 240 CHAPTER 9 TRAP ROUTINES AND SUBROUTINES The TRAP mechanism allows the user program.
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.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Chapter 5 The LC Instruction Set Architecture ISA = All of the programmer-visible components and operations of the computer memory organization.
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.
Chapter 9 TRAP Routines and Subroutines. 9-2 System Calls Certain operations require specialized knowledge and protection: specific knowledge of I/O device.
Computer Science 210 Computer Organization Machine Language Instructions: Control.
Chapter 10 And, Finally... The Stack
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Chapter 7 Assembly Language
Chapter 9 TRAP Routines and Subroutines
Chapter 7 & 9.2 Assembly Language
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
COSC121: Computer Systems: LC3 Traps and Subroutines
Chapter 7 Assembly Language
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
Introduction to Computer Engineering
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Chapter 7 Assembly Language
Introduction to Computer Engineering
Chapter 9 TRAP Routines and Subroutines
TRAP Routines Subroutines Privileged Instructions
Chapter 9 TRAP Routines and Subroutines
Chapter 7 LC-2 Assembly Language.
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Introduction to Computer Engineering
Chapter 7 Assembly Language
Chapter 9 TRAP Routines and Subroutines
Chapter 7 Assembly Language
TRAP Routines Privileged Instructions Subroutines
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Chapter 9 TRAP Routines and Subroutines
Chapter 9 TRAP Routines and Subroutines
Introduction to Computer Engineering
Introduction to Computer Engineering
Introduction to Computer Engineering
Introduction to Computer Engineering
Midterm 2 Review Chapters 4-16 LC-3
Chapter 9 TRAP Routines and Subroutines
Presentation transcript:

Computer Science 210 Computer Organization Trap Service Routines and String Input

LC-3 Trap Service Routines vector symbol routine x20 GETC read a single character (no echo) x21 OUT output a character to the monitor x22 PUTS write a string to the console x23 IN print prompt to console, read and echo character from keyboard x25 HALT halt the program The first four routines work with data in R0

System Call User program invokes system call. 2. Operating system code performs operation. 3. Returns control to user program. In LC-3, this is done through the TRAP mechanism.

LC-3 TRAP Mechanism 1. A set of service routines. part of operating system -- routines start at arbitrary addresses (convention is that system code is below x3000) up to 256 routines 2. Table of starting addresses. stored at x0000 through x00FF in memory called System Control Block in some architectures 3. TRAP instruction. used by program to transfer control to operating system 8-bit trap vector names one of the 256 service routines 4. A linkage back to the user program. want execution to resume immediately after the TRAP instruction

TRAP Instruction Trap vector Where to go How to get back identifies which system call to invoke 8-bit index into table of service routine addresses in LC-3, this table is stored in memory at 0x0000 – 0x00FF 8-bit trap vector is zero-extended into 16-bit memory address Where to go lookup starting address from table; place in PC How to get back save address of next instruction (current PC) in R7

Data Path for the TRAP NOTE: PC has already been incremented during instruction fetch stage.

RET (JMP R7) How do we transfer control back to instruction following the TRAP? We saved old PC in R7. JMP R7 gets us back to the user program at the right spot. LC-3 assembly language lets us use RET (return) in place of “JMP R7”. Must make sure that service routine does not change R7, or we won’t know where to return.

TRAP Mechanism Operation Lookup starting address. Transfer to service routine. Return (JMP R7). Will form the basis for defining our own procedures

String Input Usually terminated by a return character (ASCII 13) Use GETC to input and OUT to echo If not ASCII 13, store character in an array Otherwise, quit the loop Store a null character at the end of the characters in the array

String input with sentinel-based loop ;; Register usage: ; R0 = the input character ; R1 = the newline character ; R2 = base address of the array ; R3 = temporary working storage ; Main program code LEA R0, PROMPT ; Display the prompt PUTS LD R1, RT ; Initialize the return character LEA R2, ARRAY ; Get the base address of the array WHILE GETC ; Read and echo a character (stored in R0) OUT ADD R3, R0, R1 ; Quit if character = return BRz ENDWHILE STR R0, R2, #0 ; Store that character in the array ADD R2, R2, #1 ; Increment the address of the array cell BR WHILE ; Return to read another character ENDWHILE STR R3, R2, #0 ; Store the null character after the last input LEA R0, ARRAY ; Output the string HALT ; Main program data RT .FILL x-000D ; The return character (negated) PROMPT .STRINGZ "Enter your name: " ARRAY .BLKW 30 ; Array of 30 characters (including null) .END String input with sentinel-based loop Problem: input could overflow the array, but no data are declared below it.

Defining Subroutines Chapter 9 For Friday Defining Subroutines Chapter 9