1. 程式人生 > >彙編-十進位制輸入輸出

彙編-十進位制輸入輸出

data segment
info1 db 0dh,0ah,'input a decimal number:$'
info2 db 0dh,0ah,'output a decimal number:$'
data ends

code segment 
  assume cs:code,ds:data
main proc far
  call decibin
  call binidec
  call crlf
  call stop
main endp

decibin proc near
  lea dx,info1
  mov ah,09h
  int 21h
  mov bx,0
newchar: 
  mov ah,01
h int 21h sub al,30h jl exit cmp al,9 jg exit cbw xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,ax jmp newchar exit: ret decibin endp binidec proc near lea dx,info2 mov ah,09h int 21h mov cx,3 mov ax,bx push bx mov bx,10 LP1: xor dx,dx div bx add dl,30h;餘數在dx裡 push dx loop
LP1 mov cx,3 LP2: pop dx mov ah,02h int 21h loop LP2 pop bx ret binidec endp crlf proc near mov dl,0dh mov ah,2 int 21h mov dl,0ah int 21h ret crlf endp stop proc near mov ax,4c00h int 21h ret stop endp code ends end main