CMP430 CMP Operator

Let's say I have an MSP430 build segment below:

r15:

439c 

Memory card:

 4390: 6045 0200 9c43 6400 8844 5044 363a 0000 

code:

 448a: cmp #0x363a, 0x0(r15) 4490: jnz $+0x1c 4492: Code continues . . . 44ac: Jump to location 

The goal is to keep the Z flag high. To do this with cmp, both src and dst must be equal. If I have 363a in memory cell r15, why does it turn out that the resulting cmp does not call the Z flag?

As a result of the experiments, I found that placing 3a36 in memory r15 actually caused the Z flag, but I don’t understand why.

If anyone could tell this, I would really appreciate it.

If you need more information, I will gladly provide it.

+6
source share
1 answer

The reason is that the MSP430 is a bit endian machine.
That is, the byte in the bottom addres 0x439C interpreted as the smallest significant byte.
The byte at the top address 0x439D interpreted as the Most significant byte.
Thus, the 16-bit value in memory is actually interpreted as 0x36 + (0x3A << 8) = 0x3A36 .

This also explains why you set the Z flag if you change both bytes.

Note:
In bytes of memory, bytes are listed from left to right from lower to higher addresses.
Only for large state machines (for example, MC680x0) you can interpret the values ​​of several bytes, as they are listed in a memory dump; for small end machines (e.g. x86, MSP430) you need to re-order the bytes of the values ​​into several bytes in order to interpret them correctly.

+7
source

Source: https://habr.com/ru/post/974115/


All Articles