完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我只是有一个问题一直困扰着我,直到我发现发生了什么。仍然不知道为什么会这样,所以我推测这是一个bug。PIC是16F688,MPLAB X版本3.35,mpasm v5.68这里是可疑代码片段:MOVFW._variableSUBLW 0x10I验证MOVFW之后的值W是正确的(0x40),但是SUBLWis 0xD0而不是0x30的结果。还没有下载MPLAB的3.40版本来查看可疑代码是否与此相关。
以上来自于百度翻译 以下为原文 I just had a problem that drove me nuts until I pinpointed what was happening. Still don't know why it's happening so I'll speculate that it's a bug. PIC is 16F688, MPLAB X version 3.35, mpasm v5.68 Here's the suspect code snippet: MOVFW My_variable SUBLW 0x10 I verified that the value in W after MOVFW is correct (0x40) but the result of the SUBLW is 0xD0 instead of 0x30. Changed the code to: MOVLW 0x10 SUBWF My_variable, W That works. Haven't downloaded the 3.40 version of MPLAB to see if the suspect code works with that. |
|
相关推荐
10个回答
|
|
嗨,在进行减法时,参数的顺序很重要:0x10-0x40=0xD0(=-30),您可能还获得了/Borrow状态位。0x40-0x10=0x30,这是一个正结果值。请仔细阅读数据表中的指令代码说明,对于SUBLW,它是:从字面上减去W。伊西尔
以上来自于百度翻译 以下为原文 Hi, When doing subtraction, the order of arguments matter: 0x10 - 0x40 = 0xD0 ( = -30), you probably have got a /Borrow status bit also. 0x40 - 0x10 = 0x30, this is a positive result value. Read the instruction code explaination in datasheet carefully, for SUBLW it is: Subtract W from literal. Regards, Mysil |
|
|
|
+1如果你想换一种方式,(从W中减去字面值)使用ADDLW-0x10所以MPASM在构建时接受两个对字面值的称赞。
以上来自于百度翻译 以下为原文 +1 If you want the other way round, (Subtract literal from W) use ADDLW -0x10 so MPASM takes the two's compliment of your literal at build time. |
|
|
|
“SUBLW k”做w=k-w“SUBWF f,d”做d=f-w这显示在所有8位PIC数据表的“指令集摘要”章节中。
以上来自于百度翻译 以下为原文 "SUBLW k" does w = k - w "SUBWF f,d" does d = f - w This is shown in the "Instruction Set Summary" chapter of ALL 8-bit PIC datasheets. |
|
|
|
啊,是的,当事情不起作用时,请阅读说明。我错误地将SUBLW解释为“从W中减去字面值”,就像ADDLW是“向W添加字面值”一样,也许指令应该是SUBWL。
以上来自于百度翻译 以下为原文 Ah, yes, when things don't work, read the instructions. I made the mistake of interpreting SUBLW as "subtract literal from W" just like ADDLW is "add literal to W" Maybe the instruction should have been SUBWL. |
|
|
|
应该坚持“阅读说明书”。你已经听说过当你“假设”时发生了什么。:)
以上来自于百度翻译 以下为原文 Shoulda stuck with "read the instructions". You've heard the story about what happens when you "assume". :) |
|
|
|
如果您真的想要SUBWL,请尝试:然后从那一点开始,MPASM将理解SUBWL。在RISC指令集中有一个“从W减去字面值”操作码没有任何意义,因为它复制了“向W添加字面值”的功能!
以上来自于百度翻译 以下为原文 If you really want SUBWL, try: #define SUBWL subwl subwl macro nn addlw -nn endm then from that point onwards MPASM will understand SUBWL. There isn't any point in having a 'subtract literal from W' opcode in a RISC instruction set as it duplicates the functionality of 'add literal to W'! |
|
|
|
|
|
|
|
哎哟。我会看看它是否可以让我编辑!编辑:是的。用ADDLW替换错误指令
以上来自于百度翻译 以下为原文 Whoops. I'll see if it lets me edit! Edit: It did. Incorrect instruction replaced with ADDLW |
|
|
|
我能理解你对指令助记符的错误解释。我注意到,当我第一次使用PIC16时,指令助记符的顺序并不一致:xxxWF表示“从F中减去W”,而xxLW按相同的顺序应该表示“从W中减去字面值”,但它是OPPOSITE。所以,即使是现在,有时我必须参考数据表当我不确定或忘记。
以上来自于百度翻译 以下为原文 I can understand your mis-interpretation of the instruction mnemonic. I noticed that when I first started with PIC16. The order of the instruction mnemonics is not consistent: xxxWF means "subtract W from F", and by the same order xxxLW should mean "subtract literal from W" but it is the OPPOSITE. So, even now, sometimes I have to refer the datasheet when I'm not sure or forget. |
|
|
|
我总是忘记这样的事情。在这种情况下,我总是记得,这两个可能的命令之一可以通过相应的添加指令来仿真。这不是正确的顺序,否则子指令就没用了。
以上来自于百度翻译 以下为原文 I keep forgetting such things all the time. How I always remember in this case, is that one of the two possible orders can be emulated by the corresponding ADD instruction. This is never the correct order because otherwise the SUB instruction would be useless. |
|
|
|
只有小组成员才能发言,加入小组>>
5244 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3209 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2260 浏览 5 评论
779浏览 1评论
672浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
598浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
682浏览 0评论
579浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 13:58 , Processed in 1.955457 second(s), Total 67, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号