; *************************************************** ; *** HiLow.68 *** ; *** Tests branching instructions of Sim68k *** ; *** Tests BRA, BEQ, BGE, CMP, TST *** ; *** Also uses MOVE, ADDQ, INP, DSP, DSR and HLT *** ; *************************************************** ; Branching instructions (and status bits updating) are hard ; to verify. Here is a little game that will test some of these ; instructions. Complete your verification with your own tests. ; This is the High-Low Game. ; Here is what it would look like in Pascal: ; ; R.W := $FFFF; { Initializes R (Result) } ; C.W := $0000; { Initializes C (Counter) } ; Repeat ; Readln(D0.B) { "Random" number to find } ; Until (D0.B <> 0); { D0 must be different from 0 } ; Read (D1.B); { Player is guessing a number } ; { Player can enter 0 to exit the game } ; While (D1.B <> 0) And (R.W <> 0) Do ; Begin ; If (D1.B <> D0.B) ; then ; If (D1.B < D0.B) ; then ; R.W := $1 { Too low } ; else ; R.W := $2 { Too high } ; else ; R.W := $0; { Found! } ; Writeln (R.W); { Display the message } ; Inc(C.W); ; If R.W <> 0 ; then ; Read (D1.B) ; End; ; Writeln (C.W) { Display the number of guesses } ; Assembly Language OpCode Oper1 Oper2 ; MSB LSB MSB LSB MSL LSB ;-------------------------------------------------- ; Branch to the first instruction BRA.W @Repeat ; ; Declarations DEF.W @R, #$FFFF ; DEF.W @C, #$0000 ; DEF.W @Zero, #$0000 ; DEF.W @One, #$0001 ; DEF.W @Two, #$0002 ; ; Choose a random number not 0 LABEL @Repeat ; INP.B D0 ; BEQ.W @Repeat ; ; Player is guessing a number INP.B D1 ; LABEL @While ; TST.B D1 ; BEQ.W @End ; TST.W @R ; BEQ.W @End ; ; D1 <> D0 ? CMP.B D0, D1 ; BEQ.W @Found ; BRA.W @TooLow ; LABEL @Found ; MOVE.W @Zero, @R ; BRA.W @Display ; LABEL @TooLow ; BGE.W @TooHigh ; MOVE.W @One, @R ; BRA.W @Display ; LABEL @TooHigh ; MOVE.W @Two, @R ; ; No need for a branching instruction to @Display... LABEL @Display ; ; Display the message DSP.W @R ; ; Increment the number of guesses (C) ADDQ.W #$1, @C ; TST.W @R ; BEQ.W @End ; INP.B D1 ; LABEL @EndWhile ; BRA.W @While ; LABEL @End ; ; Display the number of guesses DSP.W @C ; HLT.B ;