I am writing simulator to microcontroller msp430. I cant understand when i should set carry bit. For example in add
instruction: 1+0x7FFF
setting carry bit or 1+0xFFFF
?
There a two different instructions that implement <
, JL (jump if less) and JLO (jump if lower).
The documentation of JL says that it
allows comparison of signed integers.
The documentation of JLO says that it
is used for the comparison of unsigned numbers.
JLO is the same as JNC, therefore, C is unsigned carry.
For the ADD
instruction, the carry bit is set on unsigned overflow.
You can deduce that from the examples in TI documents . In particular, the second example in the documentation of ADD
instruction ( page 3-22 ) says that carry occurs on ADD.B
if the result is greater than 0xff
(and for ADD
and ADDA
the limits are 0xffff
and 0xfffff
respectively - 8, 16 and 20 bits):
ADD.B #10,R5 ; Add 10 to Lowbyte of R5
JC TONI ; Carry occurred, if (R5) ≥ 246 [0Ah+0F6h]
...... ; No carry
The fact that there is a NEGATIVE bit in the msp430 status register in addition to the carry bit confirms this.
There are at least a couple of existing open-source MSP430 emulators, namely mspsim
and Avrora. I suggest to use them as reference implementations.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.