.
data segment
string1 db "a=$";
string2 db "b=$";
answear db 0,0,0,0,"$";
ansstring db "a*b=$";
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
assume cs:code,ds:data;
mov ax, data;
mov ds, ax;
mov dx,offset string1;
mov ah,9h;
int 21h;// output"a="
mov ah,1h;
int 21h;
sub al,30h;
mov bl,al;
mov al,0ah;
mul bl;
mov bl,al;//get the tens
mov ah,1h;
int 21h;
sub al,30h;
add bl,al;//get the ones
mov ah,2;
mov dl,0ah;
int 21h;
mov dl,0dh;
int 21h;
mov ax,data;
mov ds,ax;
mov dx,offset string2;
mov ah,9h;
int 21h; //output"b="
mov ah,1h;
int 21h;
sub al,30h;
mov cl,al;
mov al,0ah;
mul cl;
mov cl,al;//get the tens
mov ah,1h;
int 21h;
sub al,30h;
add cl,al;//get the ones
mov ah,2;
mov dl,0ah;
int 21h;
mov dl,0dh;
int 21h;
mov al,bl;
mul cl; //answear in ax
mov bx,0ah;
mov cx,4;
mov si,3;
ans:
mov dx,0000h;
div bx;
add dl,30h;
mov byte ptr answear+si,dl;
dec si;
loop ans;
mov ax,data;
mov ds,ax;
mov dx,offset ansstring;
mov ah,9h;
int 21h; //output"a*b="
mov ax,data;
mov ds,ax;
mov dx,offset answear;
mov ah,9h;
int 21h;
mov ah,4ch;
int 21h;
ret
ends
end start ;
ans:
mov dx,0000h;
div bx;
add dl,30h;
mov byte ptr answear+si,dl;
dec si;
loop ans;
在这一段中,若div bx;换成div bl;,则会默认为字节除,计算时会发生溢出。