我编的十进制乘法运算程序 可以4乘4 不知道哪有错误 请指教~~

kkatnknow 2011-12-13 01:23:49
title
stack segment stack
db 100 dup(?)
stack ends
data segment
buf1 dw ?
buf2 dw ?
buf3 dw ?
buf4 dw ?
buf5 dw ?
buf6 dw ?
buf7 dw ?
buf8 dw ?
buf9 dw ?
buf10 dw ?
buf11 dw ?
data ends
code segment
assume cs:code,ds:data,ss:stack
start:
mov ax,stack
mov ss,ax
mov ax,data
mov ds,ax
mov buf1,0
mov buf2,0
mov buf3,0
mov buf4,0
mov buf5,0
mov buf6,0
mov buf7,0
mov buf8,0
mov buf9,0
mov buf10,0
mov buf11,0
l1_in:
mov ah,01h
int 21h
cmp al,' '
je l2_in
mov ah,0
and al,0fh
shl buf1 ,1
mov bx,buf1
shl buf1,1
shl buf1,1
add buf1,bx
add buf1,ax
jmp l1_in
l2_in:
mov ah,01h
int 21h
cmp al,' '
je cheng
mov ah,0
and al,0fh
shl buf2,1
mov bx,buf1
shl buf2,1
shl buf2,1
add buf2,bx
add buf2,ax
jmp l2_in
cheng:
mov ax,buf1
mov bx,buf2
mul bx
out_1:
mov bx,2710h
div bx
mov buf3,ax
mov buf4,dx
mov bl,64h
div bl
mov byte ptr buf3,ah
mov byte ptr buf5,al
mov bl,0a0h
div bl
mov byte ptr buf3,ah
mov byte ptr buf6,al
mov ax,word ptr buf5
div bl
mov byte ptr buf5,ah
mov byte ptr buf7,al
mov ax,word ptr buf4
mov bl,64h
div bl
mov byte ptr buf4,ah
mov byte ptr buf8,al
mov bl,0a0h
div bl
mov byte ptr buf4,ah
mov byte ptr buf9,al
mov ax,word ptr buf8
div bl
mov byte ptr buf8,ah
mov byte ptr buf10,al
push buf10
push buf8
push buf9
push buf4
push buf7
push buf5
push buf6
push buf3
mov cx,9h
loop out_end
pop ax
mov al,ah
xor ah,ah
add al,30h
mov dl,al
mov ah,02h
int 21h
out_end:
mov ah,4ch
int 21h
code ends
end start
...全文
291 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
火狐狸 2011-12-14
  • 打赏
  • 举报
回复
断楼。
liangbch 2011-12-14
  • 打赏
  • 举报
回复
谢谢楼上,本楼给出运行结果
E:\lbc\mycode\16bitasm>lbc_demo.exe
n1=?(0<n<65536)1
n2=?(0<n<65536)1
n1*n2=1

E:\lbc\mycode\16bitasm>lbc_demo.exe
n1=?(0<n<65536)2
n2=?(0<n<65536)3
n1*n2=6

E:\lbc\mycode\16bitasm>lbc_demo.exe
n1=?(0<n<65536)14
n2=?(0<n<65536)15
n1*n2=210

E:\lbc\mycode\16bitasm>lbc_demo.exe
n1=?(0<n<65536)30000
n2=?(0<n<65536)30000
n1*n2=900000000

E:\lbc\mycode\16bitasm>lbc_demo.exe
n1=?(0<n<65536)60000
n2=?(0<n<65536)50000
n1*n2=3000000000

E:\lbc\mycode\16bitasm>lbc_demo.exe
n1=?(0<n<65536)999
n2=?(0<n<65536)999
n1*n2=998001
zara 2011-12-14
  • 打赏
  • 举报
回复
这样可以取消连续 3 次回贴限制吗
liangbch 2011-12-14
  • 打赏
  • 举报
回复
先给出代码


        TITLE lbc_test
.model small

stack segment
db 100 dup(?)
stack ends

data segment
n1 dw ?
n2 dw ?
result dd ?

in_buff db 16,0
db 16 dup (?)
prompt1 db 0dh,0ah,"n1=?(0<n<65536)$"
prompt2 db 0dh,0ah,"n2=?(0<n<65536)$"
prompt3 db 0dh,0ah,"n1*n2="
out_buff db 32 dup (?)

data ends


code segment
assume cs:code,ds:data,ss:stack

start:
mov ax,stack
mov ss,ax
mov ax,data
mov ds,ax

mov dx, offset prompt1
mov ah, 9h
int 21h
mov si, offset in_buff
call input_num
mov n1,ax

mov dx, offset prompt2
mov ah, 9h
int 21h
mov si, offset in_buff
call input_num
mov n2,ax

mov ax,n1
mov bx,n2
mul bx
mov word ptr result, ax
mov word ptr result+2,dx

mov di, offset out_buff
call output_num
mov dx, offset prompt3
mov ah, 9h
int 21h

mov ax,4c00h ; terminate program
int 21h

;input a string from standard input device
;function:
; input a string from standard input device, then convert string to a 16bit number
;input parameter:
; dx: input buff, the first char [dx], the buff max length

;output parameter
; ax: return the value of input

input_num proc

mov dx,si
mov ah,0ah
int 21h

add si,2 ;skip the first 2 char and point to the first input char
xor ax,ax ;ax return value
xor cx,cx ;clean cx
mov bx,10

loop_read_char:
mov cl,byte ptr [si] ; get a char from in_buff
sub cl,'0'
cmp cl,9
ja input_exit ;if the char <'0' or >'9', then jump out loop

mul bx
add ax,cx

inc si
jmp loop_read_char

input_exit:
ret
input_num endp


;conver a number result to output_buffer and fill '$' after number string
;function:
; conver 32 bit integer result to string
;input parameter:
; none, always convert varible result

;output parameter
; di: The address of output buffer

output_num proc
push di ;di is the address of out_buff
mov bx,10

convert_high:
xor dx,dx
mov ax,word ptr [result+2]
div bx
mov word ptr [result+2],ax

convert_low:
mov ax,word ptr [result]
div bx
mov word ptr [result],ax

add dl,'0' ;save (result % 10)+'0' to out_buffer
mov byte ptr [di],dl
inc di ;di point next position

cmp_r:
cmp word ptr [result+2],0
jnz convert_high

mov dx,0
cmp word ptr [result],0
jnz convert_low

inv_string: ;swap string head and string tail
pop si ;now si is the address of out_buff
dec di ;the di point to the last char
mov bx,di
inv_loop:
mov al,[si] ;swap char
mov ah,[di]
mov [di],al
mov [si],ah
inc si
dec di
cmp_head_tail:
cmp si,di
jb inv_loop

mov byte ptr [bx+1], '$' ; For dos ah=09, string output, the terminal char must be '$'
ret
output_num endp

code ends
end start
liangbch 2011-12-14
  • 打赏
  • 举报
回复
我发现好多初学者不懂2-10进制和进制转化,为此,专门写了一篇关于使用汇编语言做进制转化的文章。见 http://blog.csdn.net/liangbch/article/details/7071719
liangbch 2011-12-13
  • 打赏
  • 举报
回复
你能否将的程序的说一下 ?别人才能检查你的程序对不对。
1.首先是输入,输入几个数?10进制输入还是16进制输入。
2.计算部分,计算哪几个数的乘积?
3.输出部分,计算结果为几个数,以什么进制输出,10进制还是16进制。
zara 2011-12-13
  • 打赏
  • 举报
回复
感觉你这代码好乱,什么算法流程,尤其是最后的输出部分?
debug 载入自己的程序,逐段看下中间结果吧。先看第一个数到内存是否正确,然后是第二个数,运算的结果,输出部分的处理等等。自己的代码,自己会熟悉,对中间结果的判断和问题所在也容易得多。
liangbch 2011-12-13
  • 打赏
  • 举报
回复
下班了,等我吃完饭给楼主编一个示范程序。

21,458

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧