data segment
input db 'Please input number:$'
output db 'the result is:$'
data ends
stack segment
dw 128 dup(0)
stack ends
code segment
assume cs:code,ds:data,ss:stack
start:
mov ax,data
mov ds,ax
mov ah,9
lea dx,input
int 21h
mov bl,0
mov ah,1
int 21h
and al,0fh
mov cl,al
add al,al
add al,al
add al,al
add al,cl
add al,cl
add bl,al ;十位乘以10
int 21h
and al,0fh
add bl,al
sal bl,1
mov ah,9
lea dx,output
int 21h
cmp bl,100
jnb output_hundred
jmp output_ten
output_hundred:
mov ah,2
mov dl,'1'
int 21h
sub bl,100
output_ten:
mov dl,0
f1:
cmp bl,10
jnb f2
jmp output_ten_end
f2:
add dl,1
sub bl,10
jmp f1
output_ten_end:
add dl,'0'
mov ah,2
int 21h
add bl,'0'
mov dl,bl
int 21h
code ends
end start
修正一下
data segment
input db 'Please input number:$'
output db 'the result is:$'
data ends
stack segment
dw 128 dup(0)
stack ends
code segment
assume cs:code,ds:data,ss:stack
start:
mov ax,data
mov ds,ax
mov ah,9
lea dx,input
int 21h ;请输入数字
mov bl,0 ;输入第一个数字
mov ah,1
int 21h
and al,0fh
mov cl,al
add al,al
add al,al
add al,al ;乘以8
add al,cl
add al,cl ;加上两倍的数字
add bl,al ;十位乘以10
int 21h ;输入第二个数字
and al,0fh
add bl,al
sal bl,1
;设置光标的列号和行号
mov ah,3
mov bh,0
int 10h
inc dh
mov dl,0
mov ah,2
int 10h
mov ah,9
lea dx,output
int 21h ;结果是
cmp bl,100
jnb output_hundred
jmp output_ten
output_hundred:
mov ah,2
mov dl,'1'
int 21h
sub bl,100
output_ten:
mov dl,0
f1:
cmp bl,10
jnb f2
jmp output_ten_end
f2:
add dl,1
sub bl,10
jmp f1
output_ten_end:
add dl,'0'
mov ah,2
int 21h
add bl,'0'
mov dl,bl
int 21h
code ends
end start