AVR乘除法子程序Word文件下载.docx
- 文档编号:22197861
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:24
- 大小:18.54KB
AVR乘除法子程序Word文件下载.docx
《AVR乘除法子程序Word文件下载.docx》由会员分享,可在线阅读,更多相关《AVR乘除法子程序Word文件下载.docx(24页珍藏版)》请在冰豆网上搜索。
rjmpRESET;
resethandle
*"
mpy8u"
-8x8BitUnsignedMultiplication
*Numberofcycles:
65
*Lowregistersused:
None
*Highregistersused:
3(mc8u,mp8u/m8uL,m8uH)
*Note:
ResultLowbyteandthemultipliersharethesameregister.
*Thiscausesthemultipliertobeoverwrittenbytheresult.
*****SubroutineRegisterVariables
.defmc8u=r16;
multiplicand
.defmp8u=r17;
multiplier
.defm8uL=r17;
resultLowbyte
.defm8uH=r18;
resultHighbyte
.defcycle=r31
*****Code
mpy8u:
ldicycle,8
clrm8uH;
clearresultHighbyte
lsrmp8u;
shiftmultiplier
m8u:
brccnoad80;
ifcarryset
addm8uH,mc8u;
addmultiplicandtoresultHighbyte
noad80:
rorm8uH;
shiftrightresultHighbyte
rorm8uL;
rotaterightresultLbyteandmultiplier
deccycle
brnem8u
ret
*****2字节乘法子程序
--------16bit*16bit----aH.aL*bH.bL=result3.2.1.0------------
---或---16bit*8bit-----aH.aL*bL=Result3.2.1-----------------
******************************************************************
.defaL=r16;
multiplicandlowbyte//被乘数
.defaH=r17;
multiplicandhighbyte
.defbL=r18;
multiplierlowbyte//乘数
.defbH=r19;
multiplierhighbyte
.defresult0=r18;
resultbyte0(LSB)
.defresult1=r19;
resultbyte1
.defresult2=r20;
resultbyte2
.defresult3=r21;
resultbyte3(MSB)
m16_8u:
ldiR19,0
rjmpmBegin
m16_16u:
ldicycle,16
mBegin:
clrresult3;
clear2highestbytesofresult
clrresult2
lsrbH;
乘数/2
rorbL;
C<
-Rd.0Rd.0<
-Rd.1Rd.15<
-0
m16_16u1:
brccnoadd;
若Rd.0=1//(ifcarryset)
addresult2,aL;
被乘数低字节加到结果的2字节
adcresult3,aH;
被乘数高字节加到结果的3字节
noadd:
rorresult3;
shiftrightresultbyte3
rorresult2;
rotaterightresultbyte2
rorresult1;
rotateresultbyte1andmultiplierHigh
rorresult0;
rotateresultbyte0andmultiplierLow
deccycle
brnem16_16u1
div8u"
-8/8BitUnsignedDivision
*Thissubroutinedividesthetworegistervariables"
dd8u"
(dividend)and
dv8u"
(divisor).Theresultisplacedin"
dres8u"
andtheremainderin
drem8u"
.
*Numberofwords:
94+return
1(drem8u)
2(dres8u/dd8u,dv8u,cycle)
.defdrem8u=r15;
remainder
.defdres8u=r16;
result
.defdd8u=r16;
dividend
.defdv8u=r17;
divisor
.defcycle=r18
*****Code**********R16/R17=R16+R15*********************
div8u:
clrdrem8u;
clearremainderandcarry
ldicycle,9;
8+1
d8u_0:
roldd8u;
shiftleftdividend
breqd8u_2
roldrem8u;
shiftdividendintoremainder
subdrem8u,dv8u;
remainder=remainder-divisor
brccd8u_1;
ifresultnegative
adddrem8u,dv8u;
restoreremainder
clc;
clearcarrytobeshiftedintoresult
rjmpd8u_0;
else
d8u_1:
sec;
setcarrytobeshiftedintoresult
rjmpd8u_0
d8u_2:
66+return
50/58/66(Min/Avg/Max)+return
2(dres8u/dd8u,dv8u)
subdrem8u,drem8u;
shiftleftdividend
rjmpd8u_2;
setcarrytobeshiftedintoresult
brccd8u_3;
rjmpd8u_4;
d8u_3:
d8u_4:
brccd8u_5;
rjmpd8u_6;
d8u_5:
d8u_6:
brccd8u_7;
rjmpd8u_8;
d8u_7:
d8u_8:
brccd8u_9;
rjmpd8u_10;
d8u_9:
d8u_10:
brccd8u_11;
rjmpd8u_12;
d8u_11:
d8u_12:
brccd8u_13;
rjmpd8u_14;
d8u_13:
d8u_14:
brccd8u_15;
rjmpd8u_16;
d8u_15:
d8u_16:
------------------div16_8u----16/8bit----R20R19/R18=R20R19+R17R16-------------------
.defdres16uL=r19
.defdres16uH=r20
.defdd16uL=r19
.defdd16uH=r20
.defdv8u=r18
.defdcnt16u=r22
.defdrem16uL=r16
.defdrem16uH=r17
div16_8u:
clrdrem16uL;
clearremainderLowbyte
subdrem16uH,drem16uH;
clearremainderHighbyteandcarry
ldidcnt16u,17
d16u_1:
roldd16uL;
roldd16uH
decdcnt16u
breqd16u_3;
完成?
跳出
roldrem16uL;
roldrem16uH
subdrem16uL,dv8u;
brccd16u_2;
adddrem16uL,dv8u;
rjmpd16u_1;
d16u_2:
sec
rjmpd16u_1
d16u_3:
ret
--------------------------------16bit/16bit-----------------------------------------
.defdrem16uL=r14
.defdrem16uH=r15
.defdres16uL=r16
.defdres16uH=r17
.defdd16uL=r16
.defdd16uH=r17
.defdv16uL=r18
.defdv16uH=r19
.defdcnt16u=r20
div16u:
subdrem16uL,dv16uL;
sbcdrem16uH,dv16uH;
adddrem16uL,dv16uL;
adcdrem16uH,dv16uH
div16u"
-16/16BitUnsignedDivision
*Thissubroutinedividesthetwo16-bitnumbers
dd8uH:
dd8uL"
(dividend)and"
dv16uH:
dv16uL"
(divisor).
*Theresultisplacedin"
dres16uH:
dres16uL"
drem16uH:
drem16uL"
196+return
148/173/196(Min/Avg/Max)
2(drem16uL,drem16uH)
4(dres16uL/dd16uL,dres16uH/dd16uH,dv16uL,dv16uH)
.defdrem1
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- AVR 乘除 法子 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)