aboutsummaryrefslogtreecommitdiff
path: root/src/double.ms
blob: 2aa31456746b6febce125598d539c66a86436501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
; double.ms --- input double print                             -*- MiLan-VM -*-
; Double integer with a function call.
; Args and result are in callers stack frame, thus the
; caller makes space for result and frees args after the call.

; BEGIN
; LOCALS n;
0: SHIFT 1     ; make space for local variable `n'
; n := READ;
1: INPUT       ; read number to double
2: STOREB 0    ; store read number to the first local variable `n'
; n := double (n);
3: LOADB 0     ; load read number from the first local variable `n'
4: NOP         ; SHIFT 1, if there are no args and call returns
5: CALL 10     ; call double
6: STOREB 0    ; store returned value to first local variable `n'
; WRITE (n);
7: LOADB 0     ; load doubled number from the first local variable `n'
8: PRINT       ; print double number
; END
9: STOP                         ; stop

; FUNC double (n) RETURNS
; BEGIN
10: NOP                ; SHIFT N, where N is number of local variables
; RETURN (n + n);
11: LOADB -3              ; load first, and only, argument
12: LOADB -3              ; load first, and only, argument
13: ADD                   ; add it
14: STOREB -3             ; write the result into (implicit) first arg
15: RETURN 0              ; return, poping N - RETURNS args
; END
; double.ms ends here