msp430

What does the MSP430 cmp.b instruction do?


Working on the microcorruption challenge. Coming in from a little experience with MIPS and I'm still figuring out some msp430 things.

The instruction set summary doesn't have a particularly descriptive entry for the cmp.b instruction, but I can see that it is being used here in conjuction with the jne instruction. The jne description: Jump to Label if Zero-bit is reset.

455a:  f290 8500 1024 cmp.b #0x85, &0x2410
4560:  0720           jne   #0x4570 <login+0x50>

So the cmp.b is comparing the byte (as indicated by the .b suffix) of the 0x85 immediate with whatever byte value is stored in the address 0x2410, but then I can only imagine this sets a bit in some register reserved for the jne instruction (aforementioned Zero-bit) to examine in order to know whether or not it should execute the jump? If this is the case which register would that be?


Solution

  • The User's Guide says:

    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

    The status bits are stored in the status register, which is called SR or R2 (if you need to access it (which is not the case here)).

    And JNE means "jump if not equal", so all those details do not matter for understanding it.