汇编->十进制到二进制书转换的程序实现

来源:互联网 发布:淘宝个性化推荐算法 编辑:程序博客网 时间:2024/04/29 18:42

//功能:十进制转换为二进制的程序 
//作者:任嫱
//时间:2007.11.16
//学习内容:实现数值转换同时对子程序的调用学习

主要程序段:

data segment                                                   
 decimal_info db 'the decimal num is:$'
 binary_info db 'the binary num is :$'

data ends


 
code segment
 assume cs:code,ds:data
start:
 mov ax,data
 mov ds,ax
 
 lea dx,decimal_info
 mov ah ,09h 
 int 21h
 
 
 
 call decimal
 call crlf
 
 
 ;mov ah ,02h
 ;int 21h
 
 lea dx,binary_info
 mov ah ,09h 
 int 21h
 
 ;call crlf
 call binary
 


decimal proc near
 mov bx,0  ;clear bx for number
newchar:
 mov ah,1  ;keybd input
 int 21h   ;call dos
 sub al,30h  ;ASCII to binary
 jl exit   ;jump if<0
 cmp al,9d  ;is it >9d?
 jg exit   ;yes,not dec digit
 cbw    ;byte in al to word in ax
 
;(digit is now in ax)
;Multiply number in bx by 10 decimal

 xchg ax,bx  ;trade digit &number
 mov cx,10d  ;put 10 dec in cx
 mul cx   ;number times 10
 xchg ax,bx  ;trade number & digit
 
;Add digit in ax to number in bx
 add bx,ax  ;add digit to number
 jmp newchar  ;get next digit

exit :
 ret    ;return from decibin
decimal endp  ;end of decibin proc

;----------------------------------------------------
crlf proc near
 mov dl,0dh  ;carriage return
 mov ah,2  ;display function
 int 21h   ;call dos
 mov dl,0ah  ;linefeed
 mov ah,2  ;display function
 int 21h   ;call dos
 ret    ;return from crlf
crlf endp
;-----------------------------------------------------

binary proc near
 mov cx,16  ;number of digits
 
rorate:
  
 shl bx,1  ;left digit to right
 
 jb printit  ;
 mov dl,30h
 mov ah,02h
 int 21h
 jmp loop_1
; add al,7h  ;digit is A to F
 
printit:
 mov dl,31h  ;print ASCII char in DL
 mov ah,2  ;display output funct
 int 21h   ;call dos
 jmp loop_1
 
loop_1:
 loop rorate
  
 ret    ;return from binihex
binary endp  

;--------------------------------------------------------- 
 
 mov ah,4ch
 int 21h


code ends
 end start

原创粉丝点击