320 likes | 526 Views
Computer Organization Lecture 21. Subroutines, stack Interrupts, service routines Input and output, buses. Instruction flow. Most of the time: program executes sequentially unless a branch or jump requested Sometimes Programmer wishes to execute a subroutine, function, or method
E N D
Computer OrganizationLecture 21 Subroutines, stack Interrupts, service routines Input and output, buses University of Portland School of Engineering
Instruction flow • Most of the time: program executes sequentially unless a branch or jump requested • Sometimes • Programmer wishes to execute a subroutine, function, or method • An unusual event occurs internally or externally and the program needs to respond to it University of Portland School of Engineering
1 2 Caller Callee 3 4 Subroutine flow control • Program prior to sub call • Caller transfers control to Callee • Callee transfers control to Caller • Program after sub call May be nested University of Portland School of Engineering
Hardware for subroutines • Goal • Jump to some memory location • Return back to next instruction after jump (PC-next) • Requirements • Save the value of the PC-next • Modify the PC, do the jump • Restore the value of PC to PC-next University of Portland School of Engineering
MIPS subroutines • Jump-and-link: jal • Saves PC-next in $ra • Jumps to subroutine address • Jump register: jr • Jumps to address in register • jr $ra will perform return • Use these to access subroutines University of Portland School of Engineering
Subroutine programming memory memory memory Call Call jal sub Call-next Call-next sub jr $ra return PC = Call $ra = xx PC = sub $ra = Call-next PC = Call-next $ra = Call-next University of Portland School of Engineering
How do we nest subroutines? University of Portland School of Engineering
Stack memory usage Push onto stack Pop from stack $sp points to top of stack University of Portland School of Engineering
Stack operations • Push sub $sp, $sp, 4 # push $ra on stack sw $ra, ($sp) • Pop lw $ra, ($sp) # pop $ra from stack add $sp, $sp, 4 Same operations to save registers University of Portland School of Engineering
Unusual events • Three types: all require immediate action • Internal to computer • Hardware generated • Software generated (OS requests) • External to computer: only hardware generated • Notation • MIPS: exception = internal, interrupt = external • Common: everything is an interrupt University of Portland School of Engineering
Identify possible events? University of Portland School of Engineering
Hardware for interrupts • Enable/disable: turns interrupts on and off • Controller changes and response • Finish instructions (flush pipeline) • Disable interrupts • Record type of event (Cause register) • Save return address (EPC register) • Branch (vector) to specific address (0x8000 0180) • Mechanism nearly identical to jal University of Portland School of Engineering
MIPS controller state diagram • Two sources: bad opcode, overflow • Cause register written • EPC written • PC written University of Portland School of Engineering
Interrupt request map University of Portland School of Engineering
Interrupt service routine • Save any registers used: save state on stack • Perform required action • Restore registers used: restore state from stack • Enable interrupts • May be done after registers saved • Provides for nested interrupts • Return University of Portland School of Engineering
Major computer components Five classic computer components University of Portland School of Engineering
Computer components • Input: receives information from external world • Output: transmits information to external world • Memory: holds programs and data • Data path: physical route that carries info • Control: coordinates overall flow of info University of Portland School of Engineering
System bus Bus interconnects system agents University of Portland School of Engineering
Adr, Data, Control MDP16 buses University of Portland School of Engineering
Early PC buses High speed Med speed CPU’s 8080 – 80486 vintage Slow speed University of Portland School of Engineering
Pentium 4 buses North bridge 82850 300/400 MHz RDRAM DIMMS South bridge 82801 6 Slots 100 Mbit University of Portland School of Engineering
··· Agent 0 Agent n Signal 0 Signal 1 Bus ··· Signal n System view of a computer One Agent at-a-time owns the bus University of Portland School of Engineering
Example buses? University of Portland School of Engineering
Bus properties • Agents • Master: owns bus, issues requests • Slave: responds to requests from a master • Interconnections • Parallel, serial • Point-to-point, distributed • Single- and multi-master University of Portland School of Engineering
Bus properties, continued. • Electrical • Clocking: synchronous, asynchronous • Logic families: setup, hold, propagation • Physical: impedance, length, speed • Performance • Bandwidth or data rate, B/s • Turn-around time to change masters, t University of Portland School of Engineering
Find B/W of MDP16 memory? CLK = 200 ns, Width = 16-bits University of Portland School of Engineering
How do we nest subroutines? • Use stack pointer register ($sp) • Push $ra onto stack upon subroutine entry • Execute body of subroutine, may call other subroutines • Pop $ra from stack just before subroutine exit • Return from subroutine University of Portland School of Engineering
Identify possible events? • Overflow, underflow, divide-by-zero, parity or CRC error, illegal instruction • Memory or file protection (write to read-only, page fault) • Real time clock, OS request • Disk drive, CD, E-net: data transfer ready, or complete University of Portland School of Engineering
Example buses? • Uart • I/O • Address • PCI • ISA • S-ATA • USB http://en.wikipedia.org/wiki/Computer_bus University of Portland School of Engineering
Find B/W of MDP16 memory? CLK = 200 ns, Width = 16-bits University of Portland School of Engineering