| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2473 人关注过本帖
标题:[新人求助]一个简单的乘法程序,没有报错但结果不对,不知道该怎么改
只看楼主 加入收藏
z_Vincent
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-12-5
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
[新人求助]一个简单的乘法程序,没有报错但结果不对,不知道该怎么改
.386
data 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编辑过]

搜索更多相关主题的帖子: 字符串 
2016-12-05 20:33
Valenciax
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:11
帖 子:340
专家分:2482
注 册:2016-5-15
收藏
得分:20 
回复 楼主 z_Vincent
略略瞄了一下,
add buf[bx],eax
add ax,dl
楼主用什么编译器,这些型别都不对的指令 确定没有报错?
2016-12-05 22:29
快速回复:[新人求助]一个简单的乘法程序,没有报错但结果不对,不知道该怎么改
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018099 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved