我在PIC18汇编中编写了一个非常基本的程序。它要求我编写一个子程序来乘以两个16位数字。这就是我现在所拥有的:PIC汇编函数调用
;***********************************************************************
; 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
我已经是现在写的方式是,它乘以存储在第一评论,并将它们存储在注释4个寄存器注册号提及。这种运作良好,如果我只需要一次或两次这样做乘法,即我可以这样说:
mul_16ptr1 set 0x45
mul_16ptr2 set 0x47
mul_16res set 0x50
call mul_16bit
要乘0x45
和0x47
并将其存储在0x50
。问题是当我需要在不同的数据上多次调用它时,因为汇编程序不会让我“设置”任何指针两次。我尝试过使用间接访问(即使用LFSR1,LFSR2和LFSR0来存储被乘数和结果),但是后来我只是陷入了一大堆POSTINC0等等。有没有办法让这个函数调用更好的东西?
那么,如果你想保持芯片便宜,其中许多是必要的。 – 2010-08-19 18:41:10