一、实习目的与要求
掌握乘法指令和循环指令的用法。
二、实习内容
实现十进制数的乘法,被乘数和乘数均以ASCⅡ码形式放在内存中,乘积在屏幕上显示出来
三、代码
data segment
left db '45','$';定义十进制相乘左操作数
right db '23','$';定义十进制相乘右操作数
Bleft dw 0;
Bright dw 0;
result db 0;
c10 dw 10;十进制进位数
msgOne db 'The left num is:','$'
msgTwo db 0ah,0dh,'The right num is:','$'
msgThree db 0ah,0dh,'The result is:','$'
data ends
mystack segment stack
db 100 dup(?)
mystack ends
code segment
assume DS:data,CS:code
start:
mov ax,data;
mov DS,ax;
lea dx,msgOne;输出做操作数信息
mov ah,09h;
int 21h;
lea dx,left;
mov ah,09h;
int 21h;
lea dx,msgTwo;输出右操作数信息
mov ah,09h;
int 21h;
lea dx,right;
mov ah,09h;
int 21h;
lea si,left;
call changeToBinary;
mov Bleft,ax;
lea si,right;
call changeToBinary;
mov Bright,ax;
mul Bleft;
mov cx,0;
changeToDec:
mov dx,0;
cmp ax,0; 判断ax是否为0,为0则跳出循环
jz outChangeToDex;
div c10;
push dx;
inc cx;
jmp changeToDec;
outChangeToDex:
lea dx,msgThree;
mov ah,09h;
int 21h;
printResult:
pop dx;
add dl,30h;
mov ah,02h;
int 21h;
loop printResult;
mov ah,4ch; 程序退出
int 21h;
changeToBinary proc; 将字符串ASCII数字字符转换为数字
;si寄存器传递参数,ax寄存器返回结果
push bx; 保护现场
mov ax,0;
mov bh,0; bx寄存器高位置零
One:
mov bl,[si];
cmp bl,'$';
jz oneOut;
mul c10;
and bl,0fh;
add al,bl;
inc (si);
jmp one
oneOut:
pop bx;
ret
code ends
end start
四、截图
时间: 2024-10-09 20:16:45