Debian Codegraph @

help/figures/fig0638.pep

raw
1 ;File: fig0638.pep
2 ;Computer Systems, Fourth edition
3 ;Figure 6.38
4 ;
5 BR main
6 ;
7 ;******* getVect (int v[], int& n)
8 v: .EQUATE 6 ;formal parameter #2h
9 n: .EQUATE 4 ;formal parameter #2h
10 j: .EQUATE 0 ;local variable #2d
11 getVect: SUBSP 2,i ;allocate #j
12 DECI n,sf ;cin >> n
13 LDX 0,i ;for (j = 0
14 STX j,s
15 for1: CPX n,sf ; j < n
16 BRGE endFor1
17 ASLX ; an integer is two bytes
18 DECI v,sxf ; cin >> v[j]
19 LDX j,s ; j++)
20 ADDX 1,i
21 STX j,s
22 BR for1
23 endFor1: RET2 ;pop #j and retAddr
24 ;
25 ;******* putVect (int v[], int n)
26 v2: .EQUATE 6 ;formal parameter #2h
27 n2: .EQUATE 4 ;formal parameter #2d
28 j2: .EQUATE 0 ;local variable #2d
29 putVect: SUBSP 2,i ;allocate #j2
30 LDX 0,i ;for (j = 0
31 STX j2,s
32 for2: CPX n2,s ; j < n
33 BRGE endFor2
34 ASLX ; an integer is two bytes
35 DECO v2,sxf ; cout << v[j]
36 CHARO ' ',i ; << ' '
37 LDX j2,s ; i++)
38 ADDX 1,i
39 STX j2,s
40 BR for2
41 endFor2: CHARO '\n',i ;cout << endl
42 RET2 ;pop #j2 and retAddr
43 ;
44 ;******* main ()
45 vector: .EQUATE 2 ;local variable #2d8a
46 numItms: .EQUATE 0 ;local variable #2d
47 main: SUBSP 18,i ;allocate #vector #numItms
48 MOVSPA ;push address of vector
49 ADDA vector,i
50 STA -2,s
51 MOVSPA ;push address of numItms
52 ADDA numItms,i
53 STA -4,s
54 SUBSP 4,i ;push #v #n
55 CALL getVect ;getVect (vector, numItms)
56 ADDSP 4,i ;pop #n #v
57 MOVSPA ;push address of vector
58 ADDA vector,i
59 STA -2,s
60 LDA numItms,s ;push value of numItms
61 STA -4,s
62 SUBSP 4,i ;push #v2 #n2
63 CALL putVect ;putVect (vector, numItms)
64 ADDSP 4,i ;pop #n2 #v2
65 ADDSP 18,i ;deallocate #numItms #vector
66 STOP
67 .END