cmp


Compares.

[Syntax]

-

cmp reg1, reg2

-

cmp imm, reg2

 

The following can be specified for imm:

-

Absolute expression having a value of up to 32 bits

-

Relative expression

[Function]

-

Syntax "cmp reg1, reg2"

Compares the value of the register specified by the first operand with the value of the register specified by the second operand, and indicates the result using a flag. Comparison is performed by subtracting the value of the register specified by the first operand from the value of the register specified by the second operand.

-

Syntax "cmp imm, reg2"

Compares the value of the absolute expression or relative expression specified by the first operand with the value of the register specified by the second operand, and indicates the result using a flag. Comparison is performed by subtracting the value of the register specified by the first operand from the value of the register specified by the second operand.

[Description]

-

If the instruction is executed in syntax "cmp reg1, reg2", the assembler generates one cmp machine instruction.

-

If the following is specified as imm in syntax "cmp imm, reg2", the assembler generates one cmp machine instructionNote.

(a)

Absolute expression having a value in the range of -16 to +15

cmp     imm5, reg
cmp     imm5, reg

Note

The cmp machine instruction takes a register or immediate value in the range of -16 to +15 (0xFFFFFFF0 to 0xF) as the first operand.

 

-

If the following is specified as imm in syntax "cmp imm, reg2", the assembler executes instruction expansion to generate multiple machine instructions.

(a)

Absolute expression exceeding the range of -16 to +15, but within the range of -32,768 to +32,767

cmp     imm16, reg
movea   imm16, r0, r1
cmp     r1, reg

(b)

Absolute expression having a value exceeding the range of -32,768 to +32,767

If all the lower 16 bits of the value of imm are 0

cmp     imm, reg
movhi   HIGHW(imm), r0, r1
cmp     r1, reg

Else

cmp     imm, reg
mov     imm, r1
cmp     r1, reg

(c)

Relative expression having !label or %label, or that having $label for a label having a definition in the sdata/sbss-attribute section

cmp     !label, reg
movea   !label, r0, r1
cmp     r1, reg
cmp     %label, reg
movea   %label, r0, r1
cmp     r1, reg
cmp     $label, reg
movea   $label, r0, r1
cmp     r1, reg

(d)

Relative expression having #label or label, or that having $label for a label having no definition in the sdata/sbss-attribute section

cmp     #label, reg
mov     #label, r1
cmp     r1, reg
cmp     label, reg
mov     label, r1
cmp     r1, reg
cmp     $label, reg
mov     $label, r1
cmp     r1, reg

[Flag]

CY

1 if a borrow occurs from MSB (Most Significant Bit),0 if not

OV

1 if Integer-Overflow occurs, 0 if not

S

1 if the result is negative, 0 if not

Z

1 if the result is 0, 0 if not

SAT

---