我尝试this tutorial example使用EdSim51仿真器在DAC输出上创建一个斜坡:
CLR P0.7 ; enable the DAC WR line
loop:
MOV P1, A ; move data in the accumulator to the ADC inputs (on P1)
ADD A, #8 ; increase accumulator by 8
JMP loop ; jump back to loop
它工作正常。但是,ROM的03H-30H是reserved for interrupts。关于那个,我编码了
JMP 30h ; starts at address 0, 2B instruction
; reserved 03H-30H
ORG 30h
; same code as above
CLR P0.7
loop:
MOV P1, A
ADD A, #8
JMP loop
但这不起作用:DAC WR线未启用。
按照罗斯里奇的评论,我玩了一下:
使用标签按预期工作:
JMP main
ORG 30h
main:
CLR P0.7
...
但是,似乎如果提供了直接地址,则会跳过CLR P0.7
,这似乎是问题的根源。此代码也有效:
JMP 2Eh ; as tested, the next instruction will be at 30h
; ...
ORG 30h
CLR P0.7
...
此代码也有效
JMP 30h
; ...
ORG 30h
NOP
NOP ; 1 NOP doesn't work
CLR P0.7
...
但是:为什么直接地址会给PC增加2?
答案 0 :(得分:2)
JMP指令(实际上是SJMP指令)是一个相对跳转,所以看起来你的汇编器是按字面解释操作数并使用30h作为编码指令中的相对偏移操作数。由于偏移量是相对于SJMP指令之后的指令开始,因此跳转到地址30h所需的相对偏移量为2Eh。如果使用标签,则汇编程序会自行计算正确的相对偏移量。