32位乘法
- 格式:doc
- 大小:111.50 KB
- 文档页数:10
一.实验题目:用16位乘法指令完成32位无符号数乘法二.参考文献:《微型计算机原理与接口技术》第四版---中国科学技术大学出版周荷琴吴秀清编《计算机原理上机指导书》聂聪编三.实验原理:使用MUL指令,完成双字无符号数乘法程序,要求乘数和被乘数从键盘输入,结果显示于屏幕上。
如图所示:四. 软件工具:汇编器TASM,调试程序TUBOR DEBUGGER。
五.程序流程图六.程序data segment ;定义数据段tishi1 db 'please input a number(8):',0dh,0ah,'$'tishi2 db 'please input a number(8):',0dh,0ah,'$'tishi3 db 'the result is :$'chengshu1 db 12 dup(?)chengshu2 db 12 dup(?)result db 8 dup(?)result1 db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'$'data endscode segment ;代码段assume cs:code,ds:datamain proccall shuru ;调用输入call jisuan ;调用计算call shuchumov ah,4ch ;用于结束程序int 21hmain endpshuru proc ;输入乘数mov ax,datamov ds,axlea dx,tishi1 ;显示tishi1内容mov ah,09hint 21hmov dx,offset chengshu1 ;以字符串形式输入数据存放到chengshu1中,最多八个字节mov bx,dxmov [bx], byte ptr 9mov ah,0ahint 21hmov ax,datalea dx,tishi2mov ah,09hint 21hmov dx,offset chengshu2mov bx,dxmov [bx], byte ptr 9mov ah,0ahint 21hretshuru endpingaixie proc ;修改数如的数据,如果输入的是数字,ASCII减30h,否则减37hcmp ah,3ahjb bsub ah,37hjmp aa: cmp al,3ahjb csub al,37hjmp db: sub ah,30hjmp ac: sub al,30hjmp dd: mov cl,4shl al,clshr ax,clretingaixie endpjisuan procmov di,offset chengshu1 ;把输入和输出的数进行转换,然后放回到chengshu1,chengshu2中mov al,byte ptr [di+3]mov ah,byte ptr [di+2]call ingaixiemov byte ptr [di+2],almov al,byte ptr [di+5]mov ah,byte ptr [di+4]call ingaixiemov byte ptr [di+3],almov al, byte ptr [di+7]mov ah,byte ptr [di+6]call ingaixiemov byte ptr [di+4],al mov al,byte ptr [di+9]mov ah,byte ptr [di+8]call ingaixiemov byte ptr [di+5],almov di,offset chengshu2 mov al,byte ptr [di+3]mov ah,byte ptr [di+2]call ingaixiemov byte ptr [di+2],almov al,byte ptr [di+5]mov ah,byte ptr [di+4]call ingaixiemov byte ptr [di+3],almov al, byte ptr [di+7]mov ah,byte ptr [di+6]call ingaixiemov byte ptr [di+4],al mov al,byte ptr [di+9]mov ah,byte ptr [di+8]call ingaixiemov byte ptr [di+5],almov di,offset chengshu1 mov al,byte ptr [di+3]mov ah,byte ptr [di+2] mov bl,byte ptr [di+5] mov bh,byte ptr [di+4]mov di,offset chengshu2 mov cl,byte ptr [di+3]mov ch,byte ptr [di+2] mov dx,0mul cx ;高高相乘push dxmov ax,bxmov dx,0mul cx ;高低相乘push dxpush axmov di,offset chengshu1mov al,byte ptr [di+3]mov ah,byte ptr [di+2]mov bl,byte ptr [di+5]mov bh,byte ptr [di+4]mov di,offset chengshu2mov cl,byte ptr [di+5]mov ch,byte ptr [di+4]mov dx,0mul cx ;低高相乘push dxpush axmov ax,bxmov dx,0mul cx ;低低相乘push dxpush axmov di,offset resultpop ax ;把结果按方案形式累加pop bxmov byte ptr [di+7],almov byte ptr [di+6],ahmov byte ptr [di+5],blmov byte ptr [di+4],bhpop axadd [di+5],aladc [di+4],ahadc [di+3],bladc [di+2],bhpop axpop bxadd [di+5],aladc [di+4],ahadc [di+3],bladc [di+2],bhpop axpop bxadc [di+1],bladc [di],bhadd [di+3],aladc [di+2],ahadc [di+1],byte ptr 0adc [di], byte ptr 0retjisuan endpshuchu proc ;输出结果mov di,offset resultmov ax,0mov al,byte ptr [di]call outgaixiemov di,offset result1mov byte ptr [di],ahmov byte ptr [di+1],almov di,offset resultmov ax,0mov al,byte ptr [di+1]call outgaixiemov di,offset result1mov byte ptr [di+2],ah mov byte ptr [di+3],almov di,offset resultmov ax,0mov al,byte ptr [di+2] call outgaixiemov di,offset result1mov byte ptr [di+4],ah mov byte ptr [di+5],almov di,offset resultmov ax,0mov al,byte ptr [di+3] call outgaixiemov di,offset result1mov byte ptr [di+6],ah mov byte ptr [di+7],almov di,offset resultmov ax,0mov al,byte ptr [di+4] call outgaixiemov di,offset result1mov byte ptr [di+8],ah mov byte ptr [di+9],almov di,offset resultmov ax,0mov al,byte ptr [di+5] call outgaixiemov di,offset result1mov byte ptr [di+0ah],ah mov byte ptr [di+0bh],almov di,offset resultmov ax,0mov al,byte ptr [di+6]call outgaixiemov di,offset result1mov byte ptr [di+0ch],ahmov byte ptr [di+0dh],almov di,offset resultmov ax,0mov al,byte ptr [di+7]call outgaixiemov di,offset result1mov byte ptr [di+0eh],ahmov byte ptr [di+0fh],almov ax,datamov ds,axlea dx,tishi3mov ah,09int 21hlea dx,result1mov ah,09hint 21hretshuchu endpoutgaixie proc ;把要输出的转换成字符形式mov cl,4shl ax,clshr al,clcmp ah,0ahjb a2add ah,37ha1: cmp al,0ahjb a3add al,37hreta2: add ah,30hjmp a1a3: add al,30hretoutgaixie endpcode endsend main测试数据:11111111*11111111=0123456787654321AAAAAAAA*AAAAAAAA=71C71C70E38E38E40000000A*00000001=000000000000000A。