# Last modified on Tue May 30 22:17:47 PDT 1995 by heydon # # This program tests the built-in INT() predicate. # Global variables # # Strings to print in integer/non-integer cases V0 "Integer\n" V1 "Not integer\n" # # Starting/ending/factor value V2 2 V3 1000000 V4 3 # # Tab character V6 "\t" # PrintVal(x); (* Code slot 1 *) # (* Print the unparsed value of "x" followed by a tab character. *) C1 # # Print(Unparse(x)) .INCSP b1 .PUSHL s-1 .CALLEXT c2 .DECSP b1 .CALLEXT c0 .DECSP b1 # # Print("\t") .PUSHG c6 .CALLEXT c0 .DECSP b1 .RET # TestVal(x); (* Code slot 1 *) # (* "x" should be an integer. Use the solver to compute a square root # of "x". Then test if the square of the square root is an integer. # Print the original value, the square root, the square of the # square root, and the result of the test. *) C2 # # Make space for two local variables: # 1 => square root # 2 => square of square root .PUSHM3NIL b2 # # PrintVal(x) .PUSHL s-1 .CALL c1 .DECSP b1 # # Give the square root a hint of x .PUSHL s-1 .POPL s1 # # Solve for the square root .PUSHL s1 .PUSHL s-1 .SOLVE u1 u1 u1 # x[-1] = sqrt[1] * sqrt[1] b3 u1 u0 u0 # # Save the square root result .POPL s1 # # Print square root .PUSHL s1 .CALL c1 .DECSP b1 # # Compute square .PUSHL s1 .PUSHL s1 .MULTIPLY s3 .JUMP s3 .ERROR b4 .RET .POPL s2 # # Print square of sqrt .PUSHL s2 .CALL c1 .DECSP b1 # # Test if the square root is an integer .PUSHL s2 .IS-INT .DECSP b1 .FJUMP s8 .PUSHG c0 .JUMP s5 .PUSHG c1 .CALLEXT c0 .DECSP b1 # # Return .RET # PROC Main() IS (* Code slot 3 *) # VAR curr IN # curr := V2; # DO curr <= V3 -> # TestVal(curr); # curr := curr * V4 # OD # END # END; C3 # # VAR curr IN .PUSHM3NIL b1 # curr := V2; .PUSHG c2 .POPL s1 # DO curr <= V3 -> .PUSHL s1 .PUSHG c3 .AT-MOST .FJUMP s33 # # TestVal(curr); .PUSHL s1 .CALL c2 .DECSP b1 # # curr := curr * V4 .PUSHL s1 .PUSHG c4 .MULTIPLY s3 .JUMP s3 .ERROR b4 .RET .POPL s1 # # OD .JUMP s-45 # # END .RET END