[新人求助]一个简单的乘法程序,没有报错但结果不对,不知道该怎么改
.386data segment
buf db 80, 0, 80 dup(0)
xstr db 10 dup(0)
ystr db 10 dup(0)
xval dd 0
yval dd 0
data ends
code segment
assume cs:code, ds:data
;输入参数:di=目标字符串地址
;输出函数值: ax=字符串长度
input:
push cx
push dx
push si
push di
mov ah, 0Ah
mov dx, offset buf
int 21h
mov ch, 0
mov cl, buf[1]; CX=已输入的字符个数
push cx
lea si, buf[2]; mov si, (offset buf) + 2
input_next:
cmp cx, 0
je input_done
mov al, [si]
mov [di], al
add si, 1
add di, 1
sub cx, 1
jmp input_next
input_done:
mov byte ptr [di], 0
pop ax; AX=CX=字符串长度
pop di
pop si
pop dx
pop cx
ret
main:
mov ax, data
mov ds, ax
mov di, offset xstr
call input
mov cx, ax
mov si, offset xstr
mov ah,9
mov edx,[si]
int 21h
mov ax,0
call convert1
start1:
mov xval, eax
;
mov ah,2
mov dl,'*'
int 21h
;
mov di, offset ystr
call input
mov cx, ax
mov si, offset ystr
mov ah,9
mov edx,[si]
int 21h
mov ax,0
call convert2
start2:
mov yval, eax
;
mov ah,2
mov dl,0Dh
int 21h
mov ah,2
mov dl,0Ah
int 21h
;
mov eax,xval
mov ebx,yval
mul ebx
;
mov cx,0
push eax
decimal:
mov edx,0
mov ebx,10
div ebx
add dl,'0'
push dx
inc cx
cmp eax,0
jne decimal
mov di,offset buf
pop_decimal:
pop dx
mov buf[di],dl
inc di
dec cx
jnz pop_decimal
;
mov ah,9
mov edx,offset buf
int 21h
;
pop eax
push eax
mov bx,0
mov cx,32
hex:
mov eax,edx
rol eax,1
rol eax,1
rol eax,1
rol eax,1
mov edx,eax
and eax,000Fh
sub cx,1
cmp eax,0
jmp hex
cmp eax,10
jb add_it
sub eax,10
add eax,'A'
mov buf[bx],al
jmp one_digit_done
add_it:
cmp eax,0
add buf[bx],al
one_digit_done:
add bx,1
cmp cx,0
jnz hex
mov buf[bx],0Dh
mov buf[bx+1],0Ah
;
mov ah,9
mov edx,offset buf
int 21h
;
mov ah,2
mov dl,'h'
int 21h
;
pop eax
mov bx,0
mov cx,32
binary:
rol eax,1
mov edx,eax
and eax,1
add buf[bx],eax
add bx,1
sub cx,1
jnz binary
mov ah,9
mov edx,offset buf
int 21h
mov ah,2
mov dl,'B'
int 21h
;
mov ah, 4Ch
int 21h
convert1:
cmp cx,0
jmp start1
mov bx,10
mul bx
mov dl,xstr[si]
sub dl,'0'
add ax,dl
inc si
dec cx
jmp convert1
;
convert2:
cmp cx,0
jmp start2
mov bx,10
mul bx
mov dl,ystr[si]
sub dl,'0'
add ax,dl
inc si
dec cx
jmp convert2
;
code ends
end main
是一个算两输入数乘法的程序,然而没有报错但就是不能正常出效果,不知道怎么回事,求大神指教~
[此贴子已经被作者于2016-12-5 21:28编辑过]