computer organization lecture 21
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
Fall 2006
Lillevik 333f06-l21 1University of Portland School of Engineering
EE 333
Computer OrganizationLecture 21
Subroutines, stackInterrupts, service routines
Input and output, buses
Fall 2006
Lillevik 333f06-l21 2University of Portland School of Engineering
EE 333
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
Fall 2006
Lillevik 333f06-l21 3University of Portland School of Engineering
EE 333
Subroutine flow control
1. Program prior to sub call2. Caller transfers control to Callee3. Callee transfers control to Caller4. Program after sub call
Caller Callee
12
34
May be nested
Fall 2006
Lillevik 333f06-l21 4University of Portland School of Engineering
EE 333
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
Fall 2006
Lillevik 333f06-l21 5University of Portland School of Engineering
EE 333
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
Fall 2006
Lillevik 333f06-l21 6University of Portland School of Engineering
EE 333
Subroutine programming
CallCall-next
subreturn
CallCall-next
PC = Call
$ra = xx
PC = sub
$ra = Call-next
PC = Call-next
$ra = Call-next
jal sub
jr $ra
memory memory memory
Fall 2006
Lillevik 333f06-l21 7University of Portland School of Engineering
EE 333
How do we nest subroutines?
Fall 2006
Lillevik 333f06-l21 8University of Portland School of Engineering
EE 333
Stack memory usage
Push onto stack Pop from stack
$sp points to top of stack
Fall 2006
Lillevik 333f06-l21 9University of Portland School of Engineering
EE 333
Stack operations
• Pushsub $sp, $sp, 4 # push $ra on stack
sw $ra, ($sp)
• Poplw $ra, ($sp) # pop $ra from stack
add $sp, $sp, 4
Same operations to save registers
Fall 2006
Lillevik 333f06-l21 10University of Portland School of Engineering
EE 333
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
Fall 2006
Lillevik 333f06-l21 11University of Portland School of Engineering
EE 333
Identify possible events?
Fall 2006
Lillevik 333f06-l21 12University of Portland School of Engineering
EE 333
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
Fall 2006
Lillevik 333f06-l21 13University of Portland School of Engineering
EE 333
MIPS controller state diagram• Two sources: bad
opcode, overflow
• Cause register written
• EPC written
• PC written
Fall 2006
Lillevik 333f06-l21 14University of Portland School of Engineering
EE 333
Interrupt request map
Fall 2006
Lillevik 333f06-l21 15University of Portland School of Engineering
EE 333
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
Fall 2006
Lillevik 333f06-l21 16University of Portland School of Engineering
EE 333
Major computer components
Five classic computer components
Fall 2006
Lillevik 333f06-l21 17University of Portland School of Engineering
EE 333
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
Fall 2006
Lillevik 333f06-l21 18University of Portland School of Engineering
EE 333
System bus
Bus interconnects system agents
Fall 2006
Lillevik 333f06-l21 19University of Portland School of Engineering
EE 333
MDP16 busesAdr, Data,
Control
Fall 2006
Lillevik 333f06-l21 20University of Portland School of Engineering
EE 333
Early PC busesHigh speed
Med speed
Slow speed
CPU’s
8080 – 80486
vintage
Fall 2006
Lillevik 333f06-l21 21University of Portland School of Engineering
EE 333
Pentium 4 buses
82850
82801
300/400 MHzRDRAM DIMMS
6 Slots
100 Mbit
North bridge
South bridge
Fall 2006
Lillevik 333f06-l21 22University of Portland School of Engineering
EE 333
System view of a computer
One Agent at-a-time owns the bus
···
Signal 0
Signal n
Agent 0 Agent n···
BusSignal 1
Fall 2006
Lillevik 333f06-l21 23University of Portland School of Engineering
EE 333
Example buses?
Fall 2006
Lillevik 333f06-l21 24University of Portland School of Engineering
EE 333
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
Fall 2006
Lillevik 333f06-l21 25University of Portland School of Engineering
EE 333
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
Fall 2006
Lillevik 333f06-l21 26University of Portland School of Engineering
EE 333
Find B/W of MDP16 memory?
CLK = 200 ns, Width = 16-bits
Fall 2006
Lillevik 333f06-l21 27University of Portland School of Engineering
EE 333
Fall 2006
Lillevik 333f06-l21 28University of Portland School of Engineering
EE 333
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
Fall 2006
Lillevik 333f06-l21 29University of Portland School of Engineering
EE 333
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
Fall 2006
Lillevik 333f06-l21 30University of Portland School of Engineering
EE 333
Example buses?
• Uart
• I/O
• Address
• PCI
• ISA
• S-ATA
• USB
http://en.wikipedia.org/wiki/Computer_bus
Fall 2006
Lillevik 333f06-l21 31University of Portland School of Engineering
EE 333
Find B/W of MDP16 memory?
CLK = 200 ns, Width = 16-bits
snsclkTlw
0.120055
sMBs
bytes
s
bitsBW 0.2
10
2
0.1
166