lecture16

lecture16 - ECE252 Microprocessor Spring 2011 Lecture 16:...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Jie Hu, ECE/NJIT, Spring 2011 ECE252 L16-Para Passing.1 ECE252 Microprocessor Spring 2011 Lecture 16: Parameter Passing and Number Conversion Jie Hu http://web.njit.edu/~jhu/ece252/002
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Jie Hu, ECE/NJIT, Spring 2011 ECE252 L16-Para Passing.2 Block Diagram of Macintosh 512K Motherboard Processor 68000 I/O Interface 6522 Real- time clock Serial I/O 8530 Floppy disk controller System ROM RAM buffers and Mux PAL decoders Dynamic RAM 512KB Sound logic Video logic Speaker Video display Control signals Modem Printer Mouse Keyboard System bus Disk drive
Background image of page 2
Jie Hu, ECE/NJIT, Spring 2011 ECE252 L16-Para Passing.3 Review of Last Lecture Special exceptions Group 0: Reset, Bus Error, Address Error Group 1: Trace, Interrupt, Illegal, Privilege Group 2: Trap, Trapv, CHK, Divide-by-zero Exception handler
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Jie Hu, ECE/NJIT, Spring 2011 ECE252 L16-Para Passing.4 Today’s Lecture Subroutine Parameter passing by Value by Reference by Stack Number Conversion BCD to Binary Conversion Binary to BCD Conversion BCD to ASCII Conversion Binary to ASCII Conversion ASCII to Binary Conversion ASCII to BCD Conversion
Background image of page 4
Jie Hu, ECE/NJIT, Spring 2011 ECE252 L16-Para Passing.5 Subroutines and Parameter Passing Subroutine call BSR/JSR automatically saves the return address onto the stack, return instruction RTS restores the PC with saved return address from the stack What about passing parameters into subroutines and results out of subroutines? Subroutine parameter passing styles Passing parameters by value Passing parameters by references Passing parameters by using the stack int adder (int x, int y) { int z; z = x + y; return z; }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Jie Hu, ECE/NJIT, Spring 2011 ECE252 L16-Para Passing.6 Parameter Passing by Value In this method, the value of parameters are directly passed into or out of called subroutines through data/address registers Both caller and callee agree on which registers to be used The number of parameters that can be passed is limited by the number registers available MAIN MOVE.B #’G’, D0 BSR char_out ... Main Program Subroutine D0 (input value)
Background image of page 6
Jie Hu, ECE/NJIT, Spring 2011 ECE252 L16-Para Passing.7 Parameter Passing by Reference In stead of passing the value of the parameters, the memory addresses of parameters (along with the size) are passed to the subroutines Both caller and callee agree on which registers to be used Very useful when passing large amounts of data MAIN LEA MESG, A3 ;Point A3 to MSEG MOVE.W #(MESGE-MESG), D0 ;put length into D0 BSR PRINT_MSG ... MESG DC.B ‘A very longwinded message. ..’ MESGE Main Program Subroutine D0 (size) A3 (address) Data Block Address size
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Jie Hu, ECE/NJIT, Spring 2011 ECE252 L16-Para Passing.8 Parameter Passing Using the Stack A more general way to pass parameters on the stack
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/29/2012 for the course ECE 252 taught by Professor Rosenstark during the Spring '99 term at NJIT.

Page1 / 27

lecture16 - ECE252 Microprocessor Spring 2011 Lecture 16:...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online