PIC汇编函数调用

Sea*_*ean 5 microcontroller assembly pic18

我正在PIC18汇编中编写一个非常基本的程序.它要求我写一个子程序来乘以两个16位数.这就是我现在所拥有的:

;***********************************************************************
; mul_16bit: subroutine that multiplies two 16 bit numbers stored in
;    addresses mul_16ptr1, mul_16ptr1+1 and mul_16ptr2,mul_16ptr2+1 and
;    returns the 32-bit result in addresses mul_16res1 to mul_16res1+3

;***********************************************************************
mul_16bit:
             movf    mul_16ptr2, W           ;multiply the lower bytes
             mulwf   mul_16ptr1, W
             movff   PRODH, mul_16res+1
             movff   PRODL, mul_16res
             movf    mul_16ptr2+1, W                 ;multiply upper bytes
             mulwf   mul_16ptr1+1, W
             movff   PRODH, mul_16res+3
             movff   PRODL, mul_16res+2
             movf    mul_16ptr2, W           ;multiply lower byte of num2
             mulwf   mul_16ptr1+1, W       ; and upper byte of num1
             movf    PRODL, W
             addwf   mul_16res+1, F
             movf    PRODH, W
             addwfc  mul_16res+2, F
             movlw   0                                       ; add carry
             addwfc  mul_16res+3, F
             movf    mul_16ptr2+1, W                 ;multiply upper byte
                                                     ;of num1 and lower
             mulwf   mul_16ptr1, W           ; byte of num2
             movf    PRODL, W                        ;add the result to mul_16res
             addwf   mul_16res+1, F          ;...
             movf    PRODH, W                        ;...
             addwfc  mul_16res+2, F          ;...
             movlw   0                                       ; add carry
             addwfc  mul_16res+3, F
             return
Run Code Online (Sandbox Code Playgroud)

我现在写的方式是它将第一个注释中提到的注册中存储的数字相乘,并将它们存储在注释中的4个寄存器中.如果我只需要做一次或两次这样的乘法,这很有效,即我可以这样说:

mul_16ptr1   set    0x45
mul_16ptr2   set    0x47
mul_16res    set    0x50
call         mul_16bit
Run Code Online (Sandbox Code Playgroud)

乘以0x450x47存储它0x50.问题是当我需要在不同的数据上多次调用它时,因为汇编器不会让我"设置"任何指针两次.我尝试过使用间接访问(即使用LFSR1,LFSR2和LFSR0来存储被乘数和结果),但后来我只是陷入了大量的POSTINC0等等.无论如何要让这个函数调用更好的东西?

GJ.*_*GJ. 2

PIC18 下的函数通常使用专用输入变量,例如 RegA、RegB 和 RegR。于是有声明:

RegA res 2    ;16bit var
ResB res 2    ;16bit var
ResR res 4    ;32bit var
Run Code Online (Sandbox Code Playgroud)

调用 suchlike 函数如下所示:

;Constants declaration
    OperandA set 1234
    OperandB set 7777
;
;
;Prepare calling operand A   
    movlw low OperandA 
    movwf RegA 
    movlw high OperandA 
    movwf RegA + 1
;Prepare calling operand B         
    movlw low OperandB 
    movwf RegB + 0 
    movlw high OperandB 
    movwf RegB + 1
;Function call        
    call  MullAB_16bit
;Result is in RegR
Run Code Online (Sandbox Code Playgroud)