Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 从不在PIC18上运行的子程序返回_Assembly_Microcontroller_Pic_Mplab - Fatal编程技术网

Assembly 从不在PIC18上运行的子程序返回

Assembly 从不在PIC18上运行的子程序返回,assembly,microcontroller,pic,mplab,Assembly,Microcontroller,Pic,Mplab,我正在编写一个子程序来计算wreg中的设置位数,但是在子程序末尾到达return语句时,它只会无休止地重复return语句。我是新来的图片和组装,所以我肯定我刚刚做了一些愚蠢的事情,但我还没有能够解决它。任何帮助都将不胜感激 这是我的密码: COUNT equ 0x00 NUMBER equ 0x01 BITS equ 0x02 ;bitcounter subprogram counts the number of set bits in a byte

我正在编写一个子程序来计算wreg中的设置位数,但是在子程序末尾到达return语句时,它只会无休止地重复return语句。我是新来的图片和组装,所以我肯定我刚刚做了一些愚蠢的事情,但我还没有能够解决它。任何帮助都将不胜感激

这是我的密码:

COUNT       equ 0x00

NUMBER      equ 0x01

BITS        equ 0x02

;bitcounter subprogram counts the number of set bits in a byte

BITCOUNTER:

Loop1   rlcf NUMBER,f   ;rotates one bit of number into carry flag, store rotated number

    btfsc STATUS, C     ;skips next line if carry is clear

    incf COUNT, f   ;add one to count, store in count

    bcf STATUS, C   ;clear carry flag

    decfsz BITS

    goto Loop1

    movf COUNT, 0   ; put bit count into W register
return 

START

        movlw   0x0008

        movwf   BITS

        movlw   0xF2

        movwf NUMBER    ;stores input as "number"

        call BITCOUNTER

    end
试试这个

include "p18f452.inc"  ;from dir X:\Program Files (x86)\Microchip\MPASM Suite

COUNT       equ 0x00
NUMBER      equ 0x01
BITS        equ 0x02

;bitcounter subprogram counts the number of set bits in a byte
            org 0

START
            movlw   0x0008
            movwf   BITS
            movlw   0xF2
            movwf   NUMBER    ;stores input as "number"
            call    BITCOUNTER
            goto    START

BITCOUNTER:
Loop1       rlcf   NUMBER,f   ;rotates one bit of number into carry flag, store rotated number
            btfsc  STATUS, C     ;skips next line if carry is clear
            incf   COUNT, f   ;add one to count, store in count
            bcf    STATUS, C   ;clear carry flag
            decfsz BITS
            goto   Loop1
            movf   COUNT, 0   ; put bit count into W register
            return

            end
请记住,并没有MCPU配置设置,如振荡器,看门狗。。。
只需测试代码

我是PIC编程新手,到目前为止还没有向PIC上传任何代码(仍在等待程序员交付),但我认为最后的“goto start”解决了这个问题,因为PIC需要做一些事情。“goto start”指令将PIC放入循环中,因此它不必尝试和“stop”。如果没有,我认为PIC试图通过无限期地重复上一条指令来处理“无法停止”

如果是这样的话,您也可以添加以下内容(假设我设置正确):


在代码的末尾。PIC将继续运行no操作,直到您重置它(或者您可以根据需要设置中断、WDT或其他功能)。

在MPLAB下,您拥有卓越的模拟器,使用它来确定错误!我一直在使用模拟器。我所能说的是,它继续增加程序计数器,但return语句只是返回到它自己。啊,这很有效。非常感谢。只是因为没有指示它继续进行导致问题的操作吗?@Carasel:你真正的问题是你的程序是在sub-rutine启动的,而不是在START:)。不,不是这样。我在顶部有一个goto开始,我刚刚意识到我错过了这里,对不起(我正在逐步完成程序,所以会注意到这一点)。修复它的方法是在主程序部分的末尾添加goto START,以便它返回到那里,但我不知道为什么(我也不希望它最终这样做)。把那行改成nop不会有同样的效果。谢谢,我没想到照片会停下来。
loop2 nop
      goto loop2