Microchip
直播中

刘海欢

7年用户 196经验值
私信 关注
[问答]

SUBLW模拟时得到了不一致的结果

PIC16F8MPLAIDID892汇编是初学者发现PIC编程的秘密,但我理解这个命令子问题有一个问题,因为我在模拟时得到了不一致的结果。我的代码:列表P= 16F88,包括P16F88C MOVLW D’0’子’D’0最终结果是D’25’!为什么?因为0 - 0不能D’25’!它是一个价值,我将放在W,或它的价值。结果对于第一次使用值25总是不正确的。但是,当第二次和下一次重复命令时,结果会减去O’1’。我犯了什么错误?谢谢你的时间。

以上来自于百度翻译


      以下为原文

    PIC 16F88
MPLAB IDE 8.92
Assembler

I'm a beginner who discovers the secrets of PIC programming.
But I have a problem understanding this command SUBLW, because I get the incorect results when simulating.
My code:
    LIST P=16F88
    #include p16f88.inc

            movlw d'0'
            sublw d'0'

            END
Result is  d'25'! Why? Because 0 - 0 can not be d'25'!
It is one which value I will put in W, or what value it literal. The result is always incorrect for the first use of the value 25 .. But when the second and next repeats the command decreases the result o d'1'.

Where am I making a mistake?

Thx for your time.

回帖(4)

李维兴

2018-10-18 16:14:10
您的错误是允许程序运行结束指令。在结束指令之前进行调解。

以上来自于百度翻译


      以下为原文

   
Your mistake is allowing the program to run past the END directive. Add
        goto    $
immediately before the END directive.
举报

乐骞添

2018-10-18 16:22:16
谢谢你的回复,我不明白我的错误的原因。但是你的建议是有效的。数据表说明这个指令需要1个周期。因此,下一步应该是结束指令。程序如何允许TROUN通过结束指令?如果问题太广泛,你就不必向我解释了。我稍后会发现,在“发现秘密”的照片。我希望……非常…

以上来自于百度翻译


      以下为原文

    Thank you for your response.

I do not understand the cause of my mistake. But your recommendation works.

The data sheet states that this instruction will take 1 cycle. So, the next step should be the END instruction. How is the program allowed to run past the END instruction?
 
If the problem is too extensive, you do not have to explain it to me. I'll find out later, during the "discovers the secrets" of the PIC. I hope...
 
Very thx...
举报

李维兴

2018-10-18 16:36:50
在MPLAB8中,单击View & GT;观察打开窗口,并添加WReg。单击View & Gt;程序内存打开程序内存窗口。单击Bug ALL来组装程序。单击步骤执行MOVLW指令和WReg=0。Click Step Into再次执行该指令,但请执行。注意,在程序内存窗口中,它执行到第1002行和WRG=25。结束指令不是指令。它告诉汇编程序一个生成的结束。在程序存储器窗口中通知未编程的内存位置都是1位。对于14位PIC16指令,它是OpCal码0x3FFF,它恰好是汇编指令ADLW 255。记住第二步执行1000个指令(一个下位和999个ADDLW),并在第1002行停止;不要问我为什么1000,这是MPLAB模拟器的一个怪癖。不管怎样,在WRGG=0+999×255=0x3E319的情况下,加入WRG=0的999倍的结果是255。由于WREG是一个8位寄存器,下字节0x19=25十进制。现在,单击一步执行一个未编程的程序存储器,WRG减量1。这是因为AdDLW 255与8位值的AdDLW 1相同。这里的PIC设备不停止运行,因此您必须将代码放在一个循环中,例如Goto $分支到自身——无限循环。在实际的嵌入式应用程序中,代码通常在主循环中执行指令。

以上来自于百度翻译


      以下为原文

    In MPLAB8,

  • Click View > Watch to open the Watch window, and add WREG.
  • Click View > Program Memory to open the Program Memory window.
  • Click Build All to assemble your program.
  • Click Step Into to execute the MOVLW instruction and WREG = 0.
  • Click Step Into again to execute the SUBLW instruction, but notice in the Program Memory window it executes to line 1002 and WREG = 25.
 
The END directive is NOT an instruction. It tells the assembler the end of a build. Notice in the Program Memory window that unprogrammed memory locations are all 1's. For a 14-bit PIC16 instruction that is opcode 0x3FFF which happens to be the assembly instruction ADDLW 255. Remember the second Step Into executed 1000 instructions (one SUBLW and 999 ADDLW) and halted at line 1002; don't ask me why 1000, that is a quirk of the MPLAB Simulator. Anyway, adding 999 times of 255 to WREG = 0 results in WREG = 0 + 999*255 = 0x3E319. Since WREG is an 8-bit register the lower byte 0x19 = 25 in decimal. Now, clicking Step Into each time executes one unprogrammed program memory and WREG decrements by 1. That is because ADDLW 255 is same as ADDLW -1 for an 8-bit value.
 
Lesson here is the PIC device does not stop running, so you will have to put your code in a loop; e.g. GOTO $ which branches to itself -- an infinite loop. In a real embedded application your code generally executes instructions in a main loop.
 
举报

乐骞添

2018-10-18 16:49:31
非常感谢你的帮助!现在一切都清楚了。我想我们再看一看我的其他NoOB的问题。或不是?咧嘴笑:

以上来自于百度翻译


      以下为原文

    Thanks so much for your help!
 
Everything is clear for now. I think we're going to have another look at my other noob's questions. Or not?
grin:
举报

更多回帖

发帖
×
20
完善资料,
赚取积分