Review Last Lecture - Subroutine & Parameter Passing - Basic Input/Output
Review Last Lecture - Subroutine & Parameter Passing - Basic Input/Output
1
Small Test
2
15 minutes Instruction ADD 8(R1),(A)
and some of the data are
stored in memory as in the
796 picture. The instruction will be
800 ADD A, 4(R1) executed. It is known also that
804 ADD 8(R1), (A) the content of R1=1000 &
……... A=2000.
996 1000 1.What is the content of PC?
1000 500 Explain your answer (10
1004 3500 points)
1008 2000 2.Write the fetch and
…… execution cycles. (50 points)
2000 1000
3.Write the end result after
execution. (40 points)
2004 1050
3
Answer of the test question
1. The content of PC = 804, because the
instruction that will be executed is in
memory location 804
2000 1000
2004 1050
5
ASSEMBLY LANGUAGE
START 100 Load R1,N SUM EQU 200
104 Move R2,#NUM1 ORIGIN 204
108 Clear R0
N DATAWORD 100
LOOP 112 Add R0,(R2)
NUM1 RESERVE 400
116 Add R2,#4
ORIGIN 100
120 Decrement R1
START LOAD R1,N
124 Branch >0 LOOP
MOVE R2,#NUM1
128 Store R0,SUM
CLR R0
132
LOOP ADD R0,(R2)
…….
ADD R2,#4
SUM 200
DEC R1
N 204 100
BGTZ LOOP
NUM1 208
STORE R0,SUM
NUM2 212
RETURN
…….
END START
NUMn 604
6
PARAMETER PASSING
Calling Program
Load R2,N • R2, R3, and R4 are called
Move R4,#NUM1 passing parameters.
Call LISTADD • If a lot of parameters are
Store R3,SUM used, the possibility is run
out of parameters.
Subroutine • Other alternative: passing
LISTADD Clear R3 parameter is put into stack
LOOP Add R3,
(R4)+
Decrement R2
Branch>0 LOOP
Return
7
PARAMETER PASSING
Calling Program
Calling Program Load R2,N
Load R2,N Move R4,#NUM1
Move R4,#NUM1 Call LISTADD
Call LISTADD Store R3,SUM
Store R3,SUM Subroutine
Subroutine LISTADD Subtract SP, SP, #4
LISTADD Clear R3 Store R5, (SP)
LOOP Add R3, Clear R3
(R4)+ LOOP Load R5, (R4)
Decrement R2 Add R3, R3, R5
Branch>0 LOOP Add R4, R4, #4
Return Subtract R2, R2, #1
Branch if_[R2]>0 LOOP
Load R5, (SP)
Add SP, SP, #4
8
Return
PARAMETER PASSING
Move -(SP),#NUM1
Calling Program
Load -(SP),N
Load R2,N Call LISTADD
Move R4,#NUM1 Store 4(SP),SUM
16
INPUT/OUTPUT ORGANIZATION
Processor Memory
Interconecton
17
I/O INTERFACE
Address Lines
Bus Data Lines
Control Lines
Move R0,DATAIN
I/O Device
Move DATAOUT,R0
18
KIN : Keyboard Input
KIE : Keyboard Interrupt Enable
KIRQ : Keyboard Interrupt Request
23
HOMEWORK
NUM1
Level 1 =>
Initial SP 25