Given all the previous analysis, the FX-7400G program absolutely flows into the calculator.
Program BOOLOP (51 bytes):
; Performs a boolean operation upon two boolean values. Any boolean ; valued function of two boolean arguments may be specified ; ; The boolean arguments are placed into A and B. These are regarded as ; true and false as they are non-zero or zero, respetively. The code ; for the function to be performed is placed into C. The function code ; is constructed from the truth table for the desired function as ; follows: ; ; A B c ; 0 0 1 ; 0 1 2 ; 1 0 4 ; 1 1 8 ; ; The function code is the sum of the c values corresponding to true ; entries in the truth table. ; ; (Popular functions: 3 is not A, 5 is not B, 14 is A or B, 6 is ; A xor B, 8 is A and B.) ; ; Variables: ; A is the first boolean value; this value is retained ; B is the second boolean value; this value is retained ; C on entry is the function code as described above; on exit is the ; specified boolean function of A and B ; Ans is on exit the specified boolean function of A and B ; ; Symbols: ; <> is the not equal relational ; => is the conditional operator ; / is the division operator ; -> is the assignment arrow A<>0=>C/4->C ; If A, then right shift function code 2 bits B<>0=>C/2->C ; If B, then right shift function code 1 bit 2Frac ((Int C)/2)->C ; Extract result into C C ; Return result in Ans as well
And there we have it, all 16 logical operations in four statements, in a subprogram taking 51 bytes! We call the program BOOLOP, for BOOLean OPeration, and we are done.
Well, almost done. We still have the unit test to do.
Copyright © 2002 Brian Hetrick
Page last updated 27 January 2002.
Building Blocks I
Control Flow II
A First Program
Data Structures I
Building Blocks II
Data Structures II