《電子技術(shù)應(yīng)用》
您所在的位置:首頁 > 嵌入式技術(shù) > 解決方案 > PIC乘法程序

PIC乘法程序

2009-01-16
關(guān)鍵詞: 單片機 PIC

PIC乘法程序一

;*******************************************************************
;                   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

PIC乘法程序二:

;*******************************************************************
;                   8x8 Software Multiplier
;               ( Fast Version : Straight Line 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  :  35 locations
;                       # of cycles     :  37
;                       Scratch RAM     :   0 locations
;
;  This routine is optimized for speed efficiency ( straight line code )
;  For code efficiency, refer to "mult8x8S.asm" ( looped 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
;
;
 include         "picreg.h"
;
;****   Define a macro for adding & right shifting  **
;
mult    MACRO   bit             ; Begin macro
 btfsc   mulplr,bit
 addwf   H_byte,Same
 rrf     H_byte,Same
 rrf     L_byte,Same
 ENDM                    ; End of macro
;
; *****************************         Begin Multiplier Routine
mpy_F   clrf    H_byte
 clrf    L_byte
 movf    mulcnd,w        ; move the multiplicand to W reg.
 bcf     STATUS,CARRY    ; Clear the carry bit in the status Reg.
 mult    0
 mult    1
 mult    2
 mult    3
 mult    4
 mult    5
 mult    6
 mult    7
;
 retlw   0
;
;********************************************************************
;               Test Program
;*********************************************************************
main    movlw   0FF
 movwf   mulplr          ; multiplier (in mulplr)     = 0FF
 movlw   0FF
 movwf   mulcnd          ; multiplicand(in mulcnd )   = 0FF
;
 call    mpy_F           ; The result 0FF*0FF = FE01 is in locations
;                               ; H_byte & L_byte
;
self    goto    self
;
 org     01FF
 goto    main
;
 END

本站內(nèi)容除特別聲明的原創(chuàng)文章之外,轉(zhuǎn)載內(nèi)容只為傳遞更多信息,并不代表本網(wǎng)站贊同其觀點。轉(zhuǎn)載的所有的文章、圖片、音/視頻文件等資料的版權(quán)歸版權(quán)所有權(quán)人所有。本站采用的非本站原創(chuàng)文章及圖片等內(nèi)容無法一一聯(lián)系確認版權(quán)者。如涉及作品內(nèi)容、版權(quán)和其它問題,請及時通過電子郵件或電話通知我們,以便迅速采取適當措施,避免給雙方造成不必要的經(jīng)濟損失。聯(lián)系電話:010-82306118;郵箱:aet@chinaaet.com。
主站蜘蛛池模板: 色综合天天综合网国产成人网| 女人笫一次一级毛片| 欧美野外疯狂做受xxxx高潮 | 一本一道久久综合狠狠老| 久久精品国产福利电影网| 么公的又大又深又硬想要| 乱人伦xxxx国语对白| 丰满少妇大力进入| bt天堂网...www在线资源| 日韩欧美在线免费观看| 亚洲欧美日韩综合久久久久| 精品国产乱码久久久久久浪潮| 国产在线视频一区二区三区| 久久午夜福利无码1000合集| 久久人妻夜夜做天天爽| 久久亚洲国产视频| 中文在线日本免费永久18近| 一区视频免费观看| japanese日本熟妇多毛| 69sex久久精品国产麻豆| 日本成人在线看| 色黄网站成年女人色毛片| 精品无码国产污污污免费网站国产 | 国产视频你懂的| 16女性下面扒开无遮挡免费| 一本久久a久久精品亚洲| 久久AV无码精品人妻出轨| 中文字幕成人精品久久不卡| 一区二区三区视频在线播放 | 成人亚洲成人影院| 亚洲国产精品日韩专区av| 男人插女人30分钟| 又爽又刺激的视频| 色婷五月综激情亚洲综合| 国产在线一区二区三区在线| www.亚洲成在线| 国产高清一级毛片在线人| chinese乱子伦xxxx国语对白 | 久久久久综合一本久道| 三级小说第一页| 51久久夜色精品国产|