简体   繁体   English

在MSP430中进位

[英]Carry bit in msp430

I am writing simulator to microcontroller msp430. 我正在将模拟器写入微控制器msp430。 I cant understand when i should set carry bit. 我不明白何时设置进位。 For example in add instruction: 1+0x7FFF setting carry bit or 1+0xFFFF ? 例如在add指令中: 1+0x7FFF设置进位位或1+0xFFFF

There a two different instructions that implement < , JL (jump if less) and JLO (jump if lower). 有两条不同的指令实现< ,JL(如果较小则跳转)和JLO(如果较低则跳转)。

The documentation of JL says that it JL的文档说

allows comparison of signed integers. 允许比较带符号整数。

The documentation of JLO says that it JLO的文件说

is used for the comparison of unsigned numbers. 用于比较无符号数字。

JLO is the same as JNC, therefore, C is unsigned carry. JLO与JNC相同,因此C为无符号进位。

For the ADD instruction, the carry bit is set on unsigned overflow. 对于ADD指令,在无符号溢出时将进位位置1。

You can deduce that from the examples in TI documents . 您可以从TI文档中的示例推论得出。 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指令文档( 第3-22页 )中的第二个示例说,如果结果大于0xff (并且ADDADDA的限制分别为0xffff0xfffff ,则进位发生在ADD.BADD.B和20位):

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. 除了进位位以外,msp430状态寄存器中还有一个负位这一事实也证实了这一点。

There are at least a couple of existing open-source MSP430 emulators, namely mspsim and Avrora. 至少有两个现有的开源MSP430仿真器,即mspsim和Avrora。 I suggest to use them as reference implementations. 我建议将它们用作参考实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM