Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the MSP430 cmp.b instruction do?

Tags:

msp430

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?

like image 761
craybobnee Avatar asked Jan 27 '23 09:01

craybobnee


2 Answers

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.

like image 137
CL. Avatar answered Feb 04 '23 18:02

CL.


I cant comment atm to other users answers due to to low reputation but i think the following information regarding the JNE command may be useful for other users in regards to CL.'s comment.

JNE/JNZ are instructions which cause the controller to jump to the given label if the zero bit is not set. In this case the controller would jump to #0x4570 <login+0x50>

This is described in slau144j MSP430x2xx FamilyUser's Guide p. 59.

like image 33
Bassrelic Avatar answered Feb 04 '23 18:02

Bassrelic