3561
- 收藏
- 点赞
- 分享
- 举报
PIC乘除运算子程序
[code]#define STATUS 3
#define skpb skpnc ;skip if borrowed
#define skpnb skpc ;skip if no borrow
cblock 0x10
PROD:2 ;2 bytes for production
QUOT:2 ;2 bytes for quotient
PAVRA ;divider/multiplier
PAVRB ;reminder / multiplier
PAVRC ;additional byte space
mcount ;loop counter
endc
org 000h
;movlw 0x20;
;movwf PAVRA
;movlw 0x30
;movwf PAVRB
call BBYTE_DIV
goto $-1
;====================================
;PROD:2 = PAVRA * PAVRB
;====================================
BYTE_MUL
clrf PROD
clrf PROD+1
movlw .8
movwf mcount
_mul1
rlf PROD,f ;left shift 16-bit with LSB=0
bcf PROD,0
rlf PROD+1,f
rlf PAVRA,w ;make left-rotate shift
rlf PAVRA,f ;and check MSB
skpc ;skip if MSB=1
goto _mul2 ;MSB=0
;do when MSB=1
movf PAVRB,w
addwf PROD,f
skpnc
incf PROD+1,f
_mul2
decfsz mcount,f
goto _mul1
retlw 0
;====================================
;WORD divided by BYTE =
;PROD:2 / PAVRA =
;QUOT:2 = Quotient =
;PAVRB = Reminder =
;====================================
WBYTE_DIV
movf PAVRA,f
skpnz
retlw 1 ;return if divider=0
clrf PAVRB
clrf PAVRC
clrf QUOT
clrf QUOT+1
movlw .16
movwf mcount
_wdiv1
rlf QUOT,f ;adjust Quotient
rlf QUOT+1,f
bcf QUOT,0
;
rlf PROD+1,w
rlf PROD,f
rlf PROD+1,f
;
rlf PAVRB,f
rlf PAVRC,f
;
movf PAVRA,w
subwf PAVRB,f
skpb ;skip if borrow
goto _wdiv2
;if borrow
btfsc PAVRC,0
goto _wdiv2
addwf PAVRB,f
bcf PAVRC,0
goto _wdiv3
_wdiv2 ;if no borrow
bcf PAVRC,0
bsf QUOT,0
_wdiv3
decfsz mcount,f
goto _wdiv1
retlw 0
;====================================
;BYTE divided by BYTE =
;PROD[0] / PAVRA =
;QUOT[0] = Quotient =
;PAVRB = Reminder =
;====================================
BBYTE_DIV
movf PAVRA,f
skpnz
retlw 1 ;return if divider=0
clrf PAVRB ;clear reminder
clrf QUOT ;clear quotient
movlw .8
movwf mcount ;for 8 times shift
_bdiv1
rlf QUOT,f ;adjust Quotient
bcf QUOT,0 ;left shift i bit
;
rlf PROD,w ;get 1 bit, MSB first
rlf PROD,f ;do rotate shift
;
rlf PAVRB,f ;set to LSB of reminder
;
movf PAVRA,w ;reminder - divider
subwf PAVRB,f
skpb ;skip if borrow
goto _bdiv2
;do if borrowed
addwf PAVRB,f ;cancel subtraction
goto _bdiv3 ;go for next
_bdiv2 ;do if no borrow
bsf QUOT,0 ;reminder > divider
;update quotient
_bdiv3
decfsz mcount,f ;loop test
goto _bdiv1 ;do 8 times
retlw 0 ;completed
END[/code]
#define skpb skpnc ;skip if borrowed
#define skpnb skpc ;skip if no borrow
cblock 0x10
PROD:2 ;2 bytes for production
QUOT:2 ;2 bytes for quotient
PAVRA ;divider/multiplier
PAVRB ;reminder / multiplier
PAVRC ;additional byte space
mcount ;loop counter
endc
org 000h
;movlw 0x20;
;movwf PAVRA
;movlw 0x30
;movwf PAVRB
call BBYTE_DIV
goto $-1
;====================================
;PROD:2 = PAVRA * PAVRB
;====================================
BYTE_MUL
clrf PROD
clrf PROD+1
movlw .8
movwf mcount
_mul1
rlf PROD,f ;left shift 16-bit with LSB=0
bcf PROD,0
rlf PROD+1,f
rlf PAVRA,w ;make left-rotate shift
rlf PAVRA,f ;and check MSB
skpc ;skip if MSB=1
goto _mul2 ;MSB=0
;do when MSB=1
movf PAVRB,w
addwf PROD,f
skpnc
incf PROD+1,f
_mul2
decfsz mcount,f
goto _mul1
retlw 0
;====================================
;WORD divided by BYTE =
;PROD:2 / PAVRA =
;QUOT:2 = Quotient =
;PAVRB = Reminder =
;====================================
WBYTE_DIV
movf PAVRA,f
skpnz
retlw 1 ;return if divider=0
clrf PAVRB
clrf PAVRC
clrf QUOT
clrf QUOT+1
movlw .16
movwf mcount
_wdiv1
rlf QUOT,f ;adjust Quotient
rlf QUOT+1,f
bcf QUOT,0
;
rlf PROD+1,w
rlf PROD,f
rlf PROD+1,f
;
rlf PAVRB,f
rlf PAVRC,f
;
movf PAVRA,w
subwf PAVRB,f
skpb ;skip if borrow
goto _wdiv2
;if borrow
btfsc PAVRC,0
goto _wdiv2
addwf PAVRB,f
bcf PAVRC,0
goto _wdiv3
_wdiv2 ;if no borrow
bcf PAVRC,0
bsf QUOT,0
_wdiv3
decfsz mcount,f
goto _wdiv1
retlw 0
;====================================
;BYTE divided by BYTE =
;PROD[0] / PAVRA =
;QUOT[0] = Quotient =
;PAVRB = Reminder =
;====================================
BBYTE_DIV
movf PAVRA,f
skpnz
retlw 1 ;return if divider=0
clrf PAVRB ;clear reminder
clrf QUOT ;clear quotient
movlw .8
movwf mcount ;for 8 times shift
_bdiv1
rlf QUOT,f ;adjust Quotient
bcf QUOT,0 ;left shift i bit
;
rlf PROD,w ;get 1 bit, MSB first
rlf PROD,f ;do rotate shift
;
rlf PAVRB,f ;set to LSB of reminder
;
movf PAVRA,w ;reminder - divider
subwf PAVRB,f
skpb ;skip if borrow
goto _bdiv2
;do if borrowed
addwf PAVRB,f ;cancel subtraction
goto _bdiv3 ;go for next
_bdiv2 ;do if no borrow
bsf QUOT,0 ;reminder > divider
;update quotient
_bdiv3
decfsz mcount,f ;loop test
goto _bdiv1 ;do 8 times
retlw 0 ;completed
END[/code]
我来回答
回答0个
时间排序
认可量排序
暂无数据
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片
相关问答
-
2008-11-18 18:39:09
-
2015-07-06 17:28:27
-
2017-01-18 14:19:51
-
2019-01-14 09:38:06
-
2008-11-18 18:40:26
-
2008-11-24 10:22:25
-
2018-10-30 10:53:48
-
2021-03-31 17:18:03
-
2016-06-10 13:42:30
-
2024-03-05 14:34:12
-
2018-01-02 05:36:36
-
2018-12-21 16:23:35
-
2018-02-05 14:47:01
-
02025-08-26 16:43:38
-
2023-11-20 21:33:46
-
2020-09-23 18:22:59
-
2019-01-10 16:59:57
-
2018-12-13 15:46:58
-
2021-01-14 14:57:04
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
5hisi3516cv610 + gc4336p 夜晚很模糊
-
5AIISP(功能演示,SC4336P为BGGR,强制转RGGB,会导致颜色异常)
-
5rv1106使用luckfox的SDK,设备树和驱动都写好了,结果设备文件没有生成
-
5海思3516cv610中如何进行SD卡升级,根据官方文档操作,烧录进板子时,走的默认uboot,没有执行uboot升级。
-
5G610Q-IPC-38E 夜晚很暗 有什么办法解决吗 已经补光了
-
10转换模型时,SoC版本里没显示hi3516cv610芯片
-
5hisi3516cv610 使用 yolov8n 模型训练 要如何提高 这里识别的是人
-
10有人在海思平台接过SC035HGS吗
-
5关于hi3519dv500,以SD卡虚拟 U 盘操作
-
5ss928 sample_venc代码移植到openEuler24.03上执行报错 [sample_comm_vi_start_dev]-1068: vi set dev attr failed wi
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认

微信扫码分享
QQ好友