240 likes | 326 Views
Announcements. Assignment #1 due today. Tutorials. Course web page? Assignment #2: 2.13, 2.18, 2.23, due 26 Oct. at beginning of class. Lecture 5. Chapter 2 ( Cont .) Machine Instructions and Programs. Basic Input/Output Operations.
E N D
Announcements Assignment #1 due today. Tutorials. Course web page? Assignment #2: 2.13, 2.18, 2.23, due 26 Oct. at beginning of class.
Lecture 5 Chapter 2 (Cont.) Machine Instructions and Programs
Basic Input/Output Operations • Speed mismatch bet. CPU and I/O devices synchronization problem. • Input: CPU waits for a signal from keyboard that a character is ready. • Output: CPU sends character to the display and waits for a signal that it was displayed, then sends the next character. Device Interface
I/O Example Program Why MoveByte?
Stacks • Pushdown stack = Last-In-First-Out (LIFO) stack. • Operations: push and pop Push operation Pop operation Other addressing modes?
Stacks Routine for a safe push operation Routine for a safe pop operation Full stack SP=? Empty stack SP=?
Queues • First-In-First-Out (FIFO). • Two pointers at the two ends. • Circular buffer (queue).
Subroutines • Similar to C functions. Used to save space. • Any program that requires the use of the subroutine simply branches to its starting location. • A program branches to a subroutine = it calls the subroutine CALL instruction. • Main program = calling program. • Subroutine = called program. • The subroutine returns to the program that called it by executing a RETURN instruction. • The main program resumes execution continuing immediately after the instruction that called the subroutine (PC).
Subroutine Nesting and the Processor Stack • Subroutine nesting: one subroutine calls another • Link register method cannot be used. Why? • Return addresses are generated and used in a last-in–first-out order stack. • Call instruction: pushes [PC] onto top of processor stack and loads PC with the address of subroutine’s start location. • Return instruction: pops top of stack into PC.
SP SP SP SP SP SubroutinesParameter passing through processor stack Processor stack n is passed by value Numbers: by reference
SubroutinesStack frame Subroutine Move R0,–(SP) Move R1, –(SP) …… Move (SP)+,R1 Move (SP)+,R0 Add #12,SP Move (SP)+,FP Return
Logic Instructions • Not R0 • Not R0 Add #1, R0 • Negate R0
Multiplication and Division Instructions • Multiply Ri, Rj • Rj [Ri] x [Rj] • R(j+1):Rj [Ri] x [Rj] • Divide Ri,Rj • Rj [Rj] / [Ri] • Rj quotient, R(j+1) remainder
Reading Material • Textbook, Chapter 2, pages 64 - 98