Debian Codegraph @

help/figures/fig0641.pep

raw
1 ;File: fig0641.pep
2 ;Computer Systems, Fourth edition
3 ;Figure 6.41
4 ;
5 BR main
6 a: .BLOCK 2 ;global variable #2h
7 b: .BLOCK 2 ;global variable #2h
8 c: .BLOCK 2 ;global variable #2h
9 ;
10 ;******* main ()
11 main: LDA 2,i ;a = new int
12 CALL new ;#a
13 STX a,d
14 LDA 5,i ;*a = 5
15 STA a,n
16 LDA 2,i ;b = new int
17 CALL new ;#b
18 STX b,d
19 LDA 3,i ;*b = 3
20 STA b,n
21 LDA a,d ;c = a
22 STA c,d
23 LDA b,d ;a = b
24 STA a,d
25 LDA 2,i ;*a = 2 + *c
26 ADDA c,n
27 STA a,n
28 STRO msg0,d ;cout << "*a = "
29 DECO a,n ; << *a
30 CHARO '\n',i ; << endl
31 STRO msg1,d ;cout << "*b = "
32 DECO b,n ; << *b
33 CHARO '\n',i ; << endl
34 STRO msg2,d ;cout << "*c = "
35 DECO c,n ; << *c
36 CHARO '\n',i ; << endl
37 STOP
38 msg0: .ASCII "*a = \x00"
39 msg1: .ASCII "*b = \x00"
40 msg2: .ASCII "*c = \x00"
41 ;
42 ;******* operator new
43 ; Precondition: A contains number of bytes
44 ; Postcondition: X contains pointer to bytes
45 new: LDX hpPtr,d ;returned pointer
46 ADDA hpPtr,d ;allocate from heap
47 STA hpPtr,d ;update hpPtr
48 RET0
49 hpPtr: .ADDRSS heap ;address of next free byte
50 heap: .BLOCK 1 ;first byte in the heap
51 .END