使用间接寻址清除内存位置
clearing memory location with indirect adressing
嗨,我是图片汇编编码的新手。有一段代码我看不到:
BCF STATUS,IRP
MOWLW 70h
MOVWF FSR
TOP CLR INDF
INCF FSR,F
BTFSS FSR,7
GOTO TOP
好的,这是我的问题:首先这个 INDF 如何在 FSR 上工作? INCF FSR,F 这条递增指令如何作用于 F 寄存器?谢谢
This manual 来自 Microchip 将帮助您理解指令
BCF STATUS,IRP ;Bit Clear register File
;Clear bit IRP (bit7) of register STATUS (Select bank 0 and 1)
MOVLW 70h ;MOVe Literal to W register
;Set W = 70h (End of register, start of SRAM)
MOVWF FSR ;MOVe W to F
;Set FSR (File Select Register) = W = 70h
TOP ;Label
CLRF INDF ;CLeaR register File
;Clear register INDF (INDirect register File), this access memory location at FSR
INCF FSR,F ;INCrement register File
;Increment FSR and place the result in FSR (F parameter)
BTFSS FSR,7 ;Bit Test in register File, Skip if Set
;If bit7 of FSR is set skip next instruction (Break the loop)
GOTO TOP ;GO TO TOP label
PIC只有一个"internal"寄存器,叫做W.
PIC 还有一个内部 RAM(作为 SRAM 实现)。
内部 RAM 最多分为四个组,必须由程序员手动 selected。
每个 bank 为 128 字节。
寄存器实际上是内部 RAM 中的 bank 中的地址,像 STATUS 这样的寄存器只是数字 3(的地址寄存器,寄存器在每个银行上都有镜像。
每个寄存器都是 8 位宽。
每个组的第一个地址(在 PIC16 上最多 20h)用于特殊功能寄存器。
任何存储区中从 20h 到 7fh(对于 PIC16)的地址用于通用寄存器或暂存 RAM(概念与 PIC 架构一致)。
在同一版本中,从 70h 到 7fh 的地址在 bank 之间进行镜像。
PIC 不支持指令级别的间接寻址。
要读取任意内存位置的内存,必须将其写入 FSR,然后访问 INDF 将实际访问写入 的地址FSR.
由于 PIC 寄存器是 8 位的,这将允许程序员访问像 80h 这样的地址(这在普通指令中是不可能的)。
IRP 位 STATUS 处理这个:如果它是 0 banks 0 和 1 可以被 INDF(bank 0 范围从 00h 到 7fh,上面的 bank 1)如果是 1,则访问 bank 2 和 3。
所以BCF
指令清除IRP到select银行0和1。
接下来的两条指令只是设置 FSR = 70h(没有 MOVLF
指令)。
CLRF
使用间接访问清除FSR.
给出的地址
INCF
递增 FSR 并将结果写回 FSR (另一种形式是 INCF FSR, W
将递增 FSR并将结果设置在W).
BTFSS
用于中断循环,如果设置了 FSR 的第 7 位(即 FSR >= 80h)下一条指令(GOTO
) 被跳过并且循环停止。
BCF STATUS,IRP ; Clears the IRP bit of the STATUS register
MOWLW 70h ; Moves the hexadecimal value 70 into the "working register" (WREG)
MOVWF FSR ; Moves the value in WREG into the FSR register (this register is used as the address that INDF takes values from)
TOP CLR INDF ; Clears the register pointed to by the address in FSR
INCF FSR,F ; Adds one to the address in FSR (sets pointer to next address)
BTFSS FSR,7 ; Tests the highest bit of the 0x** value in the FSR register and skips the next instruction if it is 1
GOTO TOP ; Jumps to the code location with the label "TOP"
基本上,这整段代码是将所有 RAM/Memory 从 0x70 到 0x7F 设置为零,然后它运行汇编代码部分后面的任何代码。
嗨,我是图片汇编编码的新手。有一段代码我看不到:
BCF STATUS,IRP
MOWLW 70h
MOVWF FSR
TOP CLR INDF
INCF FSR,F
BTFSS FSR,7
GOTO TOP
好的,这是我的问题:首先这个 INDF 如何在 FSR 上工作? INCF FSR,F 这条递增指令如何作用于 F 寄存器?谢谢
This manual 来自 Microchip 将帮助您理解指令
BCF STATUS,IRP ;Bit Clear register File
;Clear bit IRP (bit7) of register STATUS (Select bank 0 and 1)
MOVLW 70h ;MOVe Literal to W register
;Set W = 70h (End of register, start of SRAM)
MOVWF FSR ;MOVe W to F
;Set FSR (File Select Register) = W = 70h
TOP ;Label
CLRF INDF ;CLeaR register File
;Clear register INDF (INDirect register File), this access memory location at FSR
INCF FSR,F ;INCrement register File
;Increment FSR and place the result in FSR (F parameter)
BTFSS FSR,7 ;Bit Test in register File, Skip if Set
;If bit7 of FSR is set skip next instruction (Break the loop)
GOTO TOP ;GO TO TOP label
PIC只有一个"internal"寄存器,叫做W.
PIC 还有一个内部 RAM(作为 SRAM 实现)。
内部 RAM 最多分为四个组,必须由程序员手动 selected。
每个 bank 为 128 字节。
寄存器实际上是内部 RAM 中的 bank 中的地址,像 STATUS 这样的寄存器只是数字 3(的地址寄存器,寄存器在每个银行上都有镜像。
每个寄存器都是 8 位宽。
每个组的第一个地址(在 PIC16 上最多 20h)用于特殊功能寄存器。
任何存储区中从 20h 到 7fh(对于 PIC16)的地址用于通用寄存器或暂存 RAM(概念与 PIC 架构一致)。
在同一版本中,从 70h 到 7fh 的地址在 bank 之间进行镜像。
PIC 不支持指令级别的间接寻址。
要读取任意内存位置的内存,必须将其写入 FSR,然后访问 INDF 将实际访问写入 的地址FSR.
由于 PIC 寄存器是 8 位的,这将允许程序员访问像 80h 这样的地址(这在普通指令中是不可能的)。
IRP 位 STATUS 处理这个:如果它是 0 banks 0 和 1 可以被 INDF(bank 0 范围从 00h 到 7fh,上面的 bank 1)如果是 1,则访问 bank 2 和 3。
所以BCF
指令清除IRP到select银行0和1。
接下来的两条指令只是设置 FSR = 70h(没有 MOVLF
指令)。
CLRF
使用间接访问清除FSR.
给出的地址
INCF
递增 FSR 并将结果写回 FSR (另一种形式是 INCF FSR, W
将递增 FSR并将结果设置在W).
BTFSS
用于中断循环,如果设置了 FSR 的第 7 位(即 FSR >= 80h)下一条指令(GOTO
) 被跳过并且循环停止。
BCF STATUS,IRP ; Clears the IRP bit of the STATUS register
MOWLW 70h ; Moves the hexadecimal value 70 into the "working register" (WREG)
MOVWF FSR ; Moves the value in WREG into the FSR register (this register is used as the address that INDF takes values from)
TOP CLR INDF ; Clears the register pointed to by the address in FSR
INCF FSR,F ; Adds one to the address in FSR (sets pointer to next address)
BTFSS FSR,7 ; Tests the highest bit of the 0x** value in the FSR register and skips the next instruction if it is 1
GOTO TOP ; Jumps to the code location with the label "TOP"
基本上,这整段代码是将所有 RAM/Memory 从 0x70 到 0x7F 设置为零,然后它运行汇编代码部分后面的任何代码。