aboutsummaryrefslogtreecommitdiff
path: root/src/double.ms
diff options
context:
space:
mode:
authorLibravatar Martin Michalec <martin@michalec.dev>2026-11-08 06:49:14 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-11-08 06:49:14 +0000
commit0e856ca15d8aa1499edc33c7302d4d97be404290 (patch)
treed2bb840d13c57aa17f643e6039af370255e38379 /src/double.ms
downloadlab-04-master.tar.gz
publishHEADmaster
Diffstat (limited to 'src/double.ms')
-rw-r--r--src/double.ms33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/double.ms b/src/double.ms
new file mode 100644
index 0000000..2aa3145
--- /dev/null
+++ b/src/double.ms
@@ -0,0 +1,33 @@
1; double.ms --- input double print -*- MiLan-VM -*-
2; Double integer with a function call.
3; Args and result are in callers stack frame, thus the
4; caller makes space for result and frees args after the call.
5
6; BEGIN
7; LOCALS n;
80: SHIFT 1 ; make space for local variable `n'
9; n := READ;
101: INPUT ; read number to double
112: STOREB 0 ; store read number to the first local variable `n'
12; n := double (n);
133: LOADB 0 ; load read number from the first local variable `n'
144: NOP ; SHIFT 1, if there are no args and call returns
155: CALL 10 ; call double
166: STOREB 0 ; store returned value to first local variable `n'
17; WRITE (n);
187: LOADB 0 ; load doubled number from the first local variable `n'
198: PRINT ; print double number
20; END
219: STOP ; stop
22
23; FUNC double (n) RETURNS
24; BEGIN
2510: NOP ; SHIFT N, where N is number of local variables
26; RETURN (n + n);
2711: LOADB -3 ; load first, and only, argument
2812: LOADB -3 ; load first, and only, argument
2913: ADD ; add it
3014: STOREB -3 ; write the result into (implicit) first arg
3115: RETURN 0 ; return, poping N - RETURNS args
32; END
33; double.ms ends here