Computer Science 210 Computer Organization

Slides:



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

Introduction to Computer Engineering ECE 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin –
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.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
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.
Overview The Operate Instructions - ADD, AND, NOT The Data Movement Instructions - Load, Load Address, Store Example Using Operate & Data Movement The.
Overview I/O – memory mapped programmed / interrupt driven Traps mechanism & RET Subroutines & JSR & JSRR & RET Interrupt mechanism & RTI.
Chapter 9 Overview Traps mechanism & RET Subroutines & JSR & JSRR & RET Interrupt mechanism & RTI.
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.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Overview von Neumann Model Components of a Computer Some Computer Organization Models The Computer Bus An Example Organization: The LC-3.
Computer Science 210 Computer Organization Introduction to Subroutines.
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C Chapter 7 – Subroutines These are lecture notes to accompany the book SPARC Architecture,
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
Computer Science 210 Computer Organization More on Assembler.
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.
Functions. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 JSR Instruction Jumps to a location (like.
Introduction to Computing Systems and Programming The LC-2.
Computer Science 210 Computer Organization Machine Language Instructions: Control.
Computer Science 210 Computer Organization
Chapter 14 Functions.
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Computer Science 210 Computer Organization
Chapter 9 TRAP Routines and Subroutines
Chapter 7 & 9.2 Assembly Language
Computer Science 210 Computer Organization
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
Computer Science 210 Computer Organization
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
LC-3 Details and Examples
Computer Science 210 Computer Organization
Introduction to Computer Engineering
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
HKN ECE 220: Spring 2018 Midterm 1
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
TRAP Routines Subroutines Privileged Instructions
Chapter 9 TRAP Routines and Subroutines
by Richard P. Paul, 2nd edition, 2000.
Introduction to Computer Engineering
Computer Science 210 Computer Organization
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
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
Chapter 9 TRAP Routines and Subroutines
Presentation transcript:

Computer Science 210 Computer Organization Introduction to Subroutines

Subroutines A subroutine is a program fragment that: lives in user space performs a well-defined task is invoked (called) by another user program returns control to the calling program when finished

Subroutines Like a service routine, but not part of the OS not concerned with protecting hardware resources no special privilege required Reasons for subroutines: reuse useful (and debugged!) code without having to keep typing it in divide task among multiple programmers use vendor-supplied library of useful routines

Jumps to a location (like a branch but unconditional), and saves current PC (address of next instruction) in R7. saving the return address is called “linking” target address is PC-relative (PC + Sext(IR[10:0])) bit 11 specifies addressing mode if =1, PC-relative: target address = PC + Sext(IR[10:0]) if =0, register: target address = contents of register IR[8:6]

Data Path for JSR

Just like JSR, except Register addressing mode. target address is Base Register bit 11 specifies addressing mode What important feature does JSRR provide that JSR does not?

Data Path for JSRR

Returning from Subroutine RET (JMP R7) gets us back to the calling routine. works just like in TRAP

Example: Absolute Value ;; Author: Ken Lambert ;; This program resets the value of the variable NUMBER to its absolute value, using the ABS subroutine .ORIG x3000 ;; Pseudocode design: number = abs(number) ;; Main program register usage: ; R1 = number ; Main program code LD R1, NUMBER ; Set argument for abs JSR ABS ST R1, NUMBER ; Use returned value HALT ; Data for main program NUMBER .BLKW 1 ;; Subroutine ABS ; Converts the number in R1 to its absolute value ; Input parameter R1 = the number to convert ; Output parameter R1 = the number converted ABS ADD R1, R1, #0 ; if R1 < 0 BRzp ENDABS NOT R1, R1 ; R1 = -R1 ADD R1, R1, #1 ENDABS RET .END

Interface to Trap Service Routines Registers serve as input parameters and output parameters Examples: OUT and PUTS use R0 as an input parameter GETC and IN in use R0 as an output parameter

Passing Data to Subroutines Input parameters The values passed in to a subroutine are called its input parameters. These values are needed by the subroutine to do its job. Examples: In ABS routine, R1 is the number to be converted In OUT service routine, R0 is the character to be printed. In PUTS routine, R0 is the address of the string to be printed.

Returning Data from a Subroutine Output parameters Values passed back from a subroutine are called output parameters. These are the results of the subroutine’s computation. Examples: In ABS routine, converted value is returned in R1. In GETC service routine, character read from the keyboard is returned in R0.

For Monday More Subroutines