查看: 3592|回复: 1

PIC:乘法程序

[复制链接]

该用户从未签到

发表于 2007-7-11 13:04:45 | 显示全部楼层 |阅读模式
分享到:
;*******************************************************************
;                   8x8 Software Multiplier
;               ( Code Efficient : Looped Code )
;*******************************************************************
;
;   The 16 bit result is stored in 2 bytes
;
; Before calling the subroutine " mpy ", the multiplier should
; be loaded in location " mulplr ", and the multiplicand in
; " mulcnd " . The 16 bit result is stored in locations
; H_byte & L_byte.
;
;       Performance :
;                       Program Memory  :  15 locations
;                       # of cycles     :  71
;                       Scratch RAM     :   0 locations
;
;  This routine is optimized for code efficiency ( looped code )
;  For time efficiency code refer to "mult8x8F.asm" ( straight line code )
;*******************************************************************
;
mulcnd  equ     09      ; 8 bit multiplicand
mulplr  equ     10      ; 8 bit multiplier
H_byte  equ     12      ; High byte of the 16 bit result
L_byte  equ     13      ; Low byte of the 16 bit result
count   equ     14      ; loop counter
;
;
 include         "picreg.h"
;
; *****************************         Begin Multiplier Routine
mpy_S   clrf    H_byte
 clrf    L_byte
 movlw   8
 movwf   count
 movf    mulcnd,w
 bcf     STATUS,CARRY    ; Clear the carry bit in the status Reg.
loop    rrf     mulplr
 btfsc   STATUS,CARRY
 addwf   H_byte,Same
 rrf     H_byte,Same
 rrf     L_byte,Same
 decfsz  count
 goto    loop
;
 retlw   0
;
;********************************************************************
;               Test Program
;*********************************************************************
main    movlw   0FF
 movwf   mulplr          ; multiplier (in mulplr) = 0FF
 movlw   0FF             ; multiplicand(W Reg )   = 0FF
 movwf   mulcnd
;
 call    mpy_S           ; The result 0FF*0FF = FE01 is in locations
;                               ; H_byte & L_byte
;
self    goto    self
;
 org     01FF
 goto    main
;
 END
回复

使用道具 举报

该用户从未签到

发表于 2007-7-31 13:14:53 | 显示全部楼层

RE:PIC:乘法程序

看看再说,不过也多谢楼主共享
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /1 下一条



手机版|小黑屋|与非网

GMT+8, 2025-2-16 22:58 , Processed in 0.111527 second(s), 17 queries , MemCache On.

ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

苏公网安备 32059002001037号

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.