使用 pic 微控制器清除内存位置

发布于 2024-11-06 17:28:58 字数 331 浏览 6 评论 0原文

我是 asm 和嵌入式系统的初学者。我正在查看旨在使用“间接”寄存器(或类似的东西 - 不确定)清除内存位置的代码。代码如下:

    movlw 0x20
    movwf FSR
loop    clrf INDF
    incf FSR, F
    btfsc FSR, 7
    goto loop

我没有得到 incf FSR, F 部分。指令incf需要两个操作数;它增加第一个位置的值,并将结果存储在第二个位置。在这种情况下,F将具有递增的值,那么为什么我们要对FSR进行测试呢?

I am a beginner with asm and embedded systems. I was looking at code which is meant to clear memory locations using the "indirection" register (or something like that - not sure). The code goes like:

    movlw 0x20
    movwf FSR
loop    clrf INDF
    incf FSR, F
    btfsc FSR, 7
    goto loop

I don't get the incf FSR, F part. The instruction incf takes two operands; it increments value in the first location, and stores the result in the 2nd. In this case F will have the incremented value, then why do we do a test on FSR?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

£烟消云散 2024-11-13 17:28:58

F表示文件寄存器,是一个代码d(目标)选择位; d = 0:将结果存储到W,d = 1:将结果存储到文件寄存器f。默认值为 d = 1。

编译器应该理解:

;Increment FSR byte and result store back to FSR
    incf FSR, F
    or
    incf FSR, 1
;Increment FSR byte and result store to W reg
    incf FSR, w
    or
    incf FSR, 0

F mean file register, it is a code d (destination) select bit; d = 0: store result in W, d = 1: store result in file register f. Default is d = 1.

The compiler should understand:

;Increment FSR byte and result store back to FSR
    incf FSR, F
    or
    incf FSR, 1
;Increment FSR byte and result store to W reg
    incf FSR, w
    or
    incf FSR, 0
平生欢 2024-11-13 17:28:58

incf是增量文件寄存器。第二个参数是目的地,它可以是寄存器本身(F)或工作寄存器(W),实际上是一个标志。 PIC 指令只能有一个文件寄存器地址,因此您要递增 FSR,这是指令中唯一的寄存器。不存在寄存器 F 之类的东西。

请仔细阅读适合您 PIC 风格的指令集参考。

incf is increment file register. The second argument is the destination, which is either the register itself (F) or the working register (W), and actually is a flag. PIC instructions can have only one file register address so you are incrementing FSR which is the only register in your instruction. There is no such thing as register F.

Read the instruction set reference for your flavour of PIC carefully.

来日方长 2024-11-13 17:28:58

好吧,F 只是表示内存位置。将“FSR”视为变量,即指向内存位置的指针。

            movlw 0x20     // put's the number 0x20 into the W register
            movwf FSR      // put's condense of W register in memory Loc "FSR"       
    loop    clrf INDF      // clear location pointed at by the value in W register. 
            incf FSR, F    // increment the content of the FSR
            btfsc FSR, 7   // test bit7 in the FSR and skip if set (exiting the loop)
            goto loop      // go back to loop. and do next memory location.

现在我看到的问题是,当 FSR = 0x20 时,它将退出第一次运行,因此位 7 被清除,因此它退出循环。所以我想知道btfsc是否应该是btfss。那么它会从 0x20 循环到 0xF0,这会更有意义。

Ok F just means a memory location. treat the "FSR" as just variable a pointer to a memory location.

            movlw 0x20     // put's the number 0x20 into the W register
            movwf FSR      // put's condense of W register in memory Loc "FSR"       
    loop    clrf INDF      // clear location pointed at by the value in W register. 
            incf FSR, F    // increment the content of the FSR
            btfsc FSR, 7   // test bit7 in the FSR and skip if set (exiting the loop)
            goto loop      // go back to loop. and do next memory location.

now the problem I see in this is it will exit the first run through as FSR = 0x20 thus bit 7 is clear so it exits the loop. so I wonder if the btfsc should be a btfss. then it would loop from 0x20 to 0xF0 which would make more sense.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文