TRAP Routines and Subroutines - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

TRAP Routines and Subroutines

Description:

... I/O, TRAP Routine for Halting, Saving and Restoring Registers ... Executing a TRAP Instruction. Zero extend trapvect8 to 16 bits and load into MAR ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 22
Provided by: BillL161
Category:

less

Transcript and Presenter's Notes

Title: TRAP Routines and Subroutines


1
TRAP Routines and Subroutines
  • Chapter 9

2
Outline
  • LC-3 TRAP Routines
  • Intro, TRAP Mechanism, TRAP Instruction, Complete
    Mechanism, TRAP Routines for I/O, TRAP Routine
    for Halting, Saving and Restoring Registers
  • Subroutines
  • Call/Return Mechanism, JSR(R) Instruction, TRAP
    Routine for Character Input (revisit), PUTS
    Write string to monitor, Library Routines,

3
Why TRAP?
4
TRAP Mechanism
  • Set of Service Routines
  • Table of Starting Addresses
  • TRAP Instruction
  • Linkage

5
Executing a TRAP Instruction
  • Zero extend trapvect8 to 16 bits and load into
    MAR
  • Read memory into MDR
  • R7 ? PC (The Linkage)
  • PC ? MDR

6
HOW DO WE GET BACK?
7
Compare Contrast
8
Saving Restoring Registers
  • Why should we save a register?
  • When should we save a register?
  • Who should save the register?

9
In the same vein...
  • Why do we have functions, methods, subroutines,
    procedures, etc.?

10
(No Transcript)
11
(No Transcript)
12
(No Transcript)
13
(No Transcript)
14
Call/Return Mechanism
15
What does JSR do?
16
What does JSRR do?
17
What does RET do?
18
Assembly
  • jsr sub
  • sub xxx xxx xxx
  • ...
  • ...
  • ...
  • ret
  • ld R2, far
  • jsr sub
  • far .fill sub
  • ...
  • ...
  • sub xxx xxx xxx
  • ret

19
TRAP vs JSR(R)
  • TRAP
  • Uses trap vector table
  • (Can get to from anywhere)
  • Normally do system functions
  • I/O
  • Written very carefully!
  • Typically tied into some sort of system
    protection mechanism
  • JSR(R)
  • Local (JSR)
  • Anywhere (JSRR)
  • with some work
  • Routine abstraction
  • Code reuse/libraries
  • Written
  • No protection mechanism

20
Questions?
21
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com