CMP.s <ea>, Dn Computes the difference Dn - <ea> and set the status flags (N,Z,V,C) according to the outcome of the subtraction The effect is to compare the value in register Dn against the value specified by <ea> The register Dn is NOT changed ! Only the flags are updated
Look carefully at the flags when you run the program.
You will only appreciate its power only when the CMP instruction is followed by a conditional branch/jump instruction ! (discussed next)
BLT LABEL If the status flags, at the moment that this instruction is executed, indicates that the CMP operation resulted in a "LESS THAN" condition, the CPU is instruction to "branch" or "jump" to the memory location marked by LABEL If the status flags indicates the otherwise (i.e., "NOT LESS THAN"), then the CPU will continue the execution with the next instruction (i.e., the instruction that follows the BLT instruction)
MOVE.L A, D0 D0 = A CMP.L B, D0 Compare D0 (A) against B BLT L1 Branch to location L1 if A < B MOVE.L X, D7 .... .... L1: MOVE.L Y, D7 ....
The BLT will test "A < ..." when you use variable A as the destination operation
The meaning of the jump is changed if you used variable B as the destination operand in the CMP.L instruction:
MOVE.L B, D0 D0 = B CMP.L A, D0 Compare D0 (B) against A BLT L1 Branch to location L1 if B < A MOVE.L X, D7 .... .... L1: MOVE.L Y, D7 ....
Change the program to move #4 into D0 and run it again to see the difference.
the order of the operand in the compare has a profound effect of the result, since A < B is quite different than B < A (which is A > B !!!)
|
We will examine each control statement and give the "blue print" on how the control statement can be translated into assembler code.
bra LABEL |
in cause the CPU to "branch" to the program instruction stored at the label LABEL
|
This will happen when we update the Program Counter in the CPU with the address value of LABEL !!!
|
bra LABEL <=====> move.l #LABLE, ProgramCounter |