近日有所发现,KEIL4在编译汇编语言的时候,无法发现伪指令ORG所指定的位置会覆盖生成的代码部分,比如:
ORG 0000H ;开头部分
LJMP MAIN
ORG 0003H
LJMP EXT_INT0 ;EXTERNAL INTERRUPT0
ORG 000BH
LJMP TIMER_0 ;TIMER0 INTERRUPT
ORG 0013H
LJMP EXT_INT1 ;EXTERNAL INTERRUPT1
ORG 001BH
LJMP TIMER_1 ;TIMER1 INTERRUPT
ORG 0023H
LJMP UART1 ;UART1 RECEIVED INTERRUPT
ORG 002BH
LJMP ADC ;T2
ORG 0033H
LJMP LVD
ORG 003BH
LJMP PCA
ORG 0043H
LJMP UART2 ;UART2 RECEIVED INTERRUPT
ORG 004BH
LJMP SPI
ORG 0100H
------------程序部分-----------
ORG 1700H ;数据部分(共256字节)
DB 00H,40H,41H,3EH,41H,40H,41H,3CH,41H,40H,41H,3EH,41H,40H,00H,3BH ;0 16 0F
DB 41H,40H,41H,3EH,41H,40H,41H,3CH,41H,40H,41H,3EH,41H,40H,41H,39H ;0 16 1F
DB 41H,40H,41H,3EH,41H,40H,41H,3CH,41H,40H,41H,3EH,41H,40H,41H,3BH ;0 16 2F
DB 41H,40H,41H,3EH,41H,40H,41H,3CH,41H,40H,41H,3EH,41H,40H,41H,37H ;0 16 3F
DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;0 16 4F
DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;0 16 5F
DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;0 16 6F
DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;0 16 7F
DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;0 16 8F
DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;0 16 9F
DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;0 16 AF
DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;0 16 BF
DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;0 16 CF
DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;0 16 DF
DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;0 16 EF
DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;0 16 FF
编译之后,显示CODE=6144 (1800H) ,如果将数值部分(ORG 1700H)部分COMMENT, 编译后
CODE=5926 (1726H), 显然如果包含ORG 1700H 的数值,CODE的后面26H字节会被覆盖, 上载到单片机后会出现意想不到的错误,如果不能警觉这个问题,会DEBUG到晕倒,把 ORG 改为1800H后,一切就正常了,但为什么编译器不会发现问题,没有任何警告呢? |