二进制、八进制、十进制、十六进制 之间的转换

作者在 2010-11-19 23:05:00 发布以下内容
;B\O\D\H--zhuan_huan

data segment
  str01 db 0ah,0dh,0ah,0dh,'If you want to input B,please input 1',0ah,0dh,'$'
  str02 db 'If you want to input D,please input 2',0ah,0dh,'$'
  str04 db 'If you want to quit,please input q',0ah,0dh,'$'
  str05 db 'If you want to input H,please input 3',0ah,0dh,'$'
  str06 db 'If you want to input O,please input 4',0ah,0dh,'$'
  str03 db 'Please input :$'
  str1 db 0ah,0dh,'Input D(<=4 wei):$'
  str2 db 'Output H :$'
  str3 db 'Output B :$'
  str4 db 'Output O :$'
  str6 db 'Output D :$'
  str5 db 0ah,0dh,'Input B(<=16 wei):$'
  str8 db 0ah,0dh,'Input O(<=5 wei):$'
  str7 db 0ah,0dh,'Input H(<=4 wei)(small character):$'
data ends

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

  lea dx,str01
  mov ah,09h
  int 21h
  lea dx,str02
  mov ah,09h
  int 21h
  lea dx,str05
  mov ah,09h
  int 21h
  lea dx,str06
  mov ah,09h
  int 21h
  lea dx,str04
  mov ah,09h
  int 21h
  lea dx,str03
  mov ah,09h
  int 21h
  
  mov ah,01h
  int 21h
  cmp al,'2'
  jnz WW
  call in_D
  call crlf
  call out_H
  call crlf
  call out_B
  call crlf
  call out_O
  call crlf
  call xian
  

WW:cmp al,'1'
   jnz WW2
   call in_B
   call crlf
   call out_H
   call crlf
   call out_O
   call crlf
   call out_D
   call crlf
   call xian

WW2:cmp al,'3'
   jnz WW3
   call in_H
   call crlf
   call out_B
   call crlf
   call out_O
   call crlf
   call out_D
   call crlf
   call xian
  
WW3:cmp al,'4'
   jnz WW4
   call in_O
   call crlf
   call out_B
   call crlf
   call out_H
   call crlf
   call out_D
   call crlf
   call xian

WW4:cmp al,'q'
   jz EE
   jmp start
EE:mov ax,4c00h
   int 21h  
   main endp
    
  in_D proc near  ;input D(<=4 wei)
     lea dx,str1
     mov ah,09h
     int 21h    
     mov bx,0
  L1:mov ah,01h
     int 21h
     cmp al,'0'
     jb exit
     cmp al,'9'
     ja exit
     sub al,30h
     cbw
     xchg ax,bx
     mov si,10
     mul si
     add bx,ax
     jmp L1
     exit:ret
  in_D endp  

  out_H proc near  ;Output H
     lea dx,str2
     mov ah,09h
     int 21h
     mov cx,4
  L2:push cx
     mov cl,4
     rol bx,cl
     mov dl,bl
     and dl,0fh
     add dl,30h
     cmp dl,39h
     jbe L3
     add dl,07h
  L3:mov ah,02h
     int 21h
     pop cx
     loop L2
     ret
  out_H endp

  out_B proc near  ;Output B
     lea dx,str3
     mov ah,09h
     int 21h
     mov cx,16
  L4:push cx
     rol bx,1
     mov dl,bl
     and dl,00000001b
     add dl,30h    
     mov ah,02h
     int 21h
     pop cx
     loop L4
     ret
  out_B endp

  out_O proc near  ;Output O
     lea dx,str4
     mov ah,09h
     int 21h
     mov cx,5
     rol bx,1
     mov dl,bl
     and dl,00000001b
     add dl,30h
     mov ah,02h
     int 21h
  L5:push cx    
     mov cl,3
     rol bx,cl
     mov dl,bl
     and dl,07h
     add dl,30h
     mov ah,02h
     int 21h
     pop cx
     loop L5
     ret
  out_O endp
  
  out_D proc near   ;Output D
     lea dx,str6
     mov ah,09h
     int 21h
     mov ax,bx
     mov cx,0
  T1:mov dx,0  ;important
     mov si,10
     div si
     push dx
     inc cx
     cmp ax,0
     jnz T1
  T2:pop dx
     add dl,30h
     mov ah,02h
     int 21h
     loop T2
     ret
  out_D endp

  in_B proc near   ;Input B
     lea dx,str5
     mov ah,09h
     int 21h
     mov bx,0
  L6:mov ah,01h
     int 21h
     cmp al,'0'
     jb exit1
     cmp al,'1'
     ja exit1
     sub al,30h
     cbw
     xchg ax,bx
     mov si,2
     mul si
     add bx,ax
     jmp L6
     exit1:ret
  in_B endp

  in_H proc near   ;Input H
     lea dx,str7
     mov ah,09h
     int 21h
  ZZ2:
     mov ah,01h
     int 21h
     cmp al,'0'
     jb exit3
     cmp al,'9'
     ja ZZ
     sub al,30h
     jmp ZZ1
    
  ZZ:cmp al,'a'
     jb exit3
     cmp al,'f'
     ja exit3
     sub al,57h
ZZ1:mov ah,0
     xchg ax,bx
     mov si,16
     mul si
     add bx,ax
     jmp ZZ2
     exit3:ret
  in_H endp    

  in_O proc near    ;Input O
     lea dx,str8
     mov ah,09h
     int 21h
     mov bx,0
  L9:mov ah,01h
     int 21h
     cmp al,'0'
     jb exit6
     cmp al,'7'
     ja exit6
     sub al,30h
     cbw
     xchg ax,bx
     mov si,8
     mul si
     add bx,ax
     jmp L9
     exit6:ret
  in_O endp

  crlf proc near  ;huiche-huanhang
     mov ah,02h
     mov dl,0ah
     int 21h
     mov ah,02h
     mov dl,0dh
     int 21h
     ret
  crlf endp

  xian proc near   ;Output *
     mov cx,30
   Y:mov dl,'*'
     mov ah,02h
     int 21h
     loop Y
     ret
  xian endp

code ends
end start



汇编 | 阅读 1191 次
文章评论,共0条
游客请输入验证码
文章分类
最新评论