汇编--二进制到多种进制的转换与输出

data segment
str0 db 'please input binary less than 16!',0dh,0ah,24h
str1 db 'Binary output',0dh,0ah,24h
str2 db 'Hexadecimal output',0dh,0ah,24h
str3 db 'Octal output',0dh,0ah,24h
str4 db 'Decimal unsigned number output',0dh,0ah,24h
str5 db 'The decimal symbol number output',0dh,0ah,24h
str6 db 'Thanks for your using!',0dh,0ah,24h
str7 db 0dh,0ah,24h
data ends

stacker segment stack
   dw 20 dup(?)
top label word
stacker ends
 
code segment
    assume cs:code,ds:data,ss:stacker
start proc near

    mov ax,stacker  
    mov ss,ax
    lea sp,top
    
    mov ax,data
    mov ds,ax

    lea dx,str0  
    mov ah,09h
    int 21h
    
    xor bx,bx  
    mov cx,16
L1: mov ah,01h
    int 21h
    cmp al,0dh
    je L2
    mov dl,30h
    cmp al,dl
    jb L1
    mov dl,31h
    cmp al,dl
    ja L1
    shr al,1
    rcl bx,1
    loop L1

L2: lea dx,str7  
    mov ah,09h
    int 21h
    lea dx,str1  
    mov ah,09h
    int 21h

    mov cx,16
L3: rol bx,1
    mov dl,30h
    adc dl,0
    mov ah,02h
    int 21h
    loop L3

    lea dx,str7  
    mov ah,09h
    int 21h
    lea dx,str2  
    mov ah,09h
    int 21h

    mov cx,4  
L4: push cx
    mov cl,4
    rol bx,cl
    mov al,bl
    and al,15
    cmp al,9
    jbe L5
    add al,7
L5: add al,30h
    mov dl,al
    mov ah,02h
    int 21h
    pop cx
    loop L4

    lea dx,str7  
    mov ah,09h
    int 21h
    lea dx,str3  
    mov ah,09h
    int 21h

    rol bx,1  
    mov al,30h
    adc al,0
    mov dl,al
    mov ah,02h
    int 21h

    mov cx,5
L6: push cx
    mov cl,3
    rol bx,cl
    mov al,bl
    and al,7
    add al,30h
    mov dl,al
    mov ah,02h
    int 21h
    pop cx
    loop L6

    lea dx,str7  
    mov ah,09h
    int 21h
    lea dx,str4  
    mov ah,09h
    int 21h

    mov ax,bx  
    mov si,10
    mov cx,0
L7: xor dx,dx
    div si
    push dx
    inc cx
    cmp ax,0
    ja L7
    
L8: pop dx
    add dl,30h
    mov ah,02h
    int 21h
    loop L8

    lea dx,str7  
    mov ah,09h
    int 21h
    lea dx,str5  
    mov ah,09h
    int 21h
 
    or bx,bx  
    jns L9
    mov dl,2dh
    mov ah,02h
    int 21h
    neg bx
L9: mov ax,bx
    mov si,10
    mov cx,0
L10:xor dx,dx
    div si
    push dx
    inc cx
    cmp ax,0
    ja L10
    
L11:pop dx
    add dl,30h
    mov ah,02h
    int 21h
    loop L11

    lea dx,str7  
    mov ah,09h
    int 21h
    lea dx,str6  
    mov ah,09h
    int 21h
    
    mov ah,4ch
    int 21h
start endp
code ends
    end start
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值