| 1 |
;File: fig0629.pep |
| 2 |
;Computer Systems, Fourth edition |
| 3 |
;Figure 6.29 |
| 4 |
; |
| 5 |
BR main |
| 6 |
; |
| 7 |
;******* void rect (int& p, int w, int h) |
| 8 |
p: .EQUATE 6 ;formal parameter #2h |
| 9 |
w: .EQUATE 4 ;formal parameter #2d |
| 10 |
h: .EQUATE 2 ;formal parameter #2d |
| 11 |
rect: LDA w,s ;p = (w + h) * 2 |
| 12 |
ADDA h,s |
| 13 |
ASLA |
| 14 |
STA p,sf |
| 15 |
RET0 ;pop retAddr |
| 16 |
; |
| 17 |
;******* main () |
| 18 |
perim: .EQUATE 4 ;local variable #2d |
| 19 |
width: .EQUATE 2 ;local variable #2d |
| 20 |
height: .EQUATE 0 ;local variable #2d |
| 21 |
main: SUBSP 6,i ;allocate #perim #width #height |
| 22 |
STRO msg1,d ;cout << "Enter width: " |
| 23 |
DECI width,s ;cin >> width |
| 24 |
STRO msg2,d ;cout << "Enter height: " |
| 25 |
DECI height,s ;cin >> height |
| 26 |
MOVSPA ;push the address of perim |
| 27 |
ADDA perim,i |
| 28 |
STA -2,s |
| 29 |
LDA width,s ;push the value of width |
| 30 |
STA -4,s |
| 31 |
LDA height,s ;push the value of height |
| 32 |
STA -6,s |
| 33 |
SUBSP 6,i ;push #p #w #h |
| 34 |
CALL rect ;rect (perim, width, height) |
| 35 |
ra1: ADDSP 6,i ;pop #h #w #p |
| 36 |
STRO msg3,d ;cout << "perim = " |
| 37 |
DECO perim,s ; << perim |
| 38 |
CHARO '\n',i ; << endl |
| 39 |
ADDSP 6,i ;deallocate #height #width #perim |
| 40 |
STOP |
| 41 |
msg1: .ASCII "Enter width: \x00" |
| 42 |
msg2: .ASCII "Enter height: \x00" |
| 43 |
msg3: .ASCII "perim = \x00" |
| 44 |
.END |