Texas Instruments MSP430x1xx User Manual page 70

Texas instruments modules and peripherals user's guide
Table of Contents

Advertisement

Instruction Set
CMP[.W]
Compare source and destination
CMP.B
Compare source and destination
Syntax
CMP
CMP.B
Operation
dst + .NOT.src + 1
or
(dst − src)
Description
The source operand is subtracted from the destination operand. This is
accomplished by adding the 1s complement of the source operand plus 1. The
two operands are not affected and the result is not stored; only the status bits
are affected.
Status Bits
N: Set if result is negative, reset if positive (src >= dst)
Z: Set if result is zero, reset otherwise (src = dst)
C: Set if there is a carry from the MSB of the result, reset otherwise
V: Set if an arithmetic overflow occurs, otherwise reset
Mode Bits
OSCOFF, CPUOFF, and GIE are not affected.
Example
R5 and R6 are compared. If they are equal, the program continues at the label
EQUAL.
CMP
JEQ
Example
Two RAM blocks are compared. If they are not equal, the program branches
to the label ERROR.
L$1
Example
The RAM bytes addressed by EDE and TONI are compared. If they are equal,
the program continues at the label EQUAL.
RISC 16−Bit CPU
3-34
src,dst
or
CMP.W
src,dst
R5,R6
; R5 = R6?
EQUAL
; YES, JUMP
MOV
#NUM,R5
MOV
#BLOCK1,R6
MOV
#BLOCK2,R7
CMP
@R6+,0(R7)
JNZ
ERROR
INCD
R7
DEC
R5
JNZ
L$1
CMP.B EDE,TONI
JEQ
EQUAL
src,dst
; number of words to be compared
; BLOCK1 start address in R6
; BLOCK2 start address in R7
; Are Words equal? R6 increments
; No, branch to ERROR
; Increment R7 pointer
; Are all words compared?
; No, another compare
; MEM(EDE) = MEM(TONI)?
; YES, JUMP

Advertisement

Table of Contents
loading

Table of Contents