汇编语言怎么显示一个正整数

来源:百度知道 编辑:UC知道 时间:2024/06/23 00:58:44
从键盘上输入一个正整数,汇编语言怎么显示一个正整数!谢谢各位大虾的赐教!非常感谢!
从键盘上输入一个正整数,汇编语言怎么在显示器上显示一个正整数!谢谢各位大虾的赐教!非常感谢!

;思路:
;1.从键盘接收数据存入BX寄存器
;2.显示BX寄存器中的数据
;3.分别用子程序(相当于函数)实现
data segment
str db 'input(the max is 65535):$'
data ends

code segment
assume cs:code,ds:data
main proc near
start:
mov ax,data
mov ds,ax

mov dx,offset str
mov ah,09h
int 21h

call crlf

call decibin;从键盘接收数据存入BX寄存器
call crlf;回车换行
call bini;显示数据

mov ah,4ch;返回DOS
int 21h
ret
main endp

decibin proc near;接收数字
mov bx,0
newchar:
mov ah,1
int 21h
sub al,30h
jl exit
cmp al,9d
jg exit
cbw
xchg ax,bx
mov cx,10d
mul cx
xchg ax,bx
add bx,ax
jmp newchar
exit:
ret
decibin endp

bini proc near;显示数字,最大为65535
mov cx,10000d ;因为不知道接收的是多少位
call bin ;所以显示是统一为5位,如25,则显示00025
mov cx,1000d
call bin
mov cx,100d
call bin