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

PIC乘法程序

2009-01-16
關鍵詞: 單片機 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

本站內容除特別聲明的原創文章之外,轉載內容只為傳遞更多信息,并不代表本網站贊同其觀點。轉載的所有的文章、圖片、音/視頻文件等資料的版權歸版權所有權人所有。本站采用的非本站原創文章及圖片等內容無法一一聯系確認版權者。如涉及作品內容、版權和其它問題,請及時通過電子郵件或電話通知我們,以便迅速采取適當措施,避免給雙方造成不必要的經濟損失。聯系電話:010-82306118;郵箱:aet@chinaaet.com。
主站蜘蛛池模板: 久久精品天天中文字幕人妻| 人妻少妇久久中文字幕| www.人人干| 国内揄拍国内精品视频| www四虎在线高清| 成年人视频在线观看免费| 久久精品国产99国产| 欧美中文在线观看| 亚洲欧美日韩在线观看播放| 狼色视频在线观免费观看| 十八岁的天空完整版在线观看| 久久久久亚洲精品中文字幕| 欧洲美熟女乱又伦免费视频| 亚洲电影第1页| 狠狠久久精品中文字幕无码| 再深点灬舒服灬太大了动祝视频| 老师别揉我胸啊嗯上课呢视频| 国产免费av片在线观看| 黑人巨大人精品欧美三区| 国产真实乱freesex| 曰批视频免费40分钟试看天天| 国产高清在线a视频大全| _妓院_一钑片_免看黄大片| 好吊色青青青国产在线观看| 一级黄色大毛片| 极品虎白女在线观看一线天| 亚洲日韩乱码中文无码蜜桃臀 | 美女视频黄a视频全免费网站一区 美女视频黄a视频全免费网站色 | 免费a级毛片网站| 精品久久久久久无码人妻热| 卡一卡2卡3卡精品网站| 羞羞歪歪汗汗漫画| 四虎国产精品永久在线| 老外粗猛长爽的视频| 国产一区二区三区免费播放| 蜜桃麻豆www久久国产精品| 国产乱子伦精品无码码专区| 被公连续侵犯中文字幕| 国产午夜av秒播在线观看| 韩国三级hd中文字幕| 国内揄拍国内精品|