; 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