Lecture 14
Announcements
1 Qui 21 Regrading
2 programs
3 Quit 2
Topics
1 LC 3 CODE FOR ARRAYS
2 PASSING ARRAY
to FUNCTION
Y 3 USING POINTERS
IN FUNCTION
I
25
Example f SYMBAL TABLE
int ac4TCte V name type scope offset
xp at 4
X int Ltd
and ac 33
aus 3 x
123 act 1 CD x acid’s
atos o T ia
25
Stk Ro RS 4 store
compilerstepsi
1 GET BASE
ADDRESS CRS 3
7 2
EVAL THE INDEX 27
3 multiply8 INDEX SIZE
OF ELEMENT
2 1 121
4 ADD INDEX TOTHE BASE ADDRESS
125 3 2
125 1
5 1ST ELEMENT
2 AEXT
3
BASE 425 3 AND Ro Ro Of
clear120
index App Ro Ro 3 Ro 33
Ckish
ADD 14,125
3 Rik babeApp07A
LDK 1221125 4
R2 indeh
att
App Rz R R2 1232 411
3
RS 37 2
STR Ko Nz O
a ROCS
RST Ww
1 1 1
125 3 1
125,17 2
t
f
100 2
98
FUNCTIONS IN ITH ARRAY PARAMETER
PASS BY VALUE
int add Cinta int’t a
return tty
3 qnyxuo
42
yk.intad cx.y
g
IIEt
a
PASS BY REFERENCE
void snap int P
int g t
int Rs
int temp t.qooxo.ge
te
q temp OTB 20 m
y ota
main
int gih2X 10
int 8
20
t t
swap can DI
Point Rly
201 10
int Svm cint datacs int site
int s 0
inti’s
for Ciro I size
ift
s St data i
3
returns
3
int main E
int se y Z
int acts
n ro
4
a sum cats aIi a
w IT
function call code Off 2 3
Frain
AND 1201120 O n
RS
4 IADD Ro Ro Yi y 0
ADD 1261126 Ii
SIK Ro Rb O r pushy
ADD Ro 125 6 tacos
I
ADD 126 126 I
5172 126 Rb o Pusha
LC 3 code FOR DEFININTON Of SVM
PREAMBLE
int Srm cintdatacs int site
126 7 i indef
Oint s 0 r5
Sinti oIdR Pk 1
for Ci 0 IL Sl Et
ift R.A z
2 s s data i R y 3
old126 T3 w
444 SIZEreturns s
3
i Load BASE
ADDRESS
a 3
2 EVAL INDEX
3 index size
4 ADD INDEX
TOTHE BASE
Se StCdataced
5 1ST ELEMENT
LDN Efi 125 4
Ro data.pt
R Ri Rs t R
index Ci 2 43
I
APP Ro Ro RI Ro A
data I
R RI Ro Hoi Ro
data Cig 7
LDR R 125 o Cds
ADD 1201 Ro Ri St data I
7 o store value to S
Examples of function
calling
T.in qg
base
the 400 elements
it
int aGood
int bCooT
F
i