汇编语言: 编写一个程序,从键盘输入一个 0~65535 之间的 10 进制无符号数,然后以 16 进制 和四进制数形式显示出所输入的数。

**
更多习题答案见

https://github.com/Lemonreds/assembly-solution

**

编写一个程序,从键盘输入一个 0~65535 之间的 10 进制无符号数,然后以 16 进制
和四进制数形式显示出所输入的数。
2017年6月5日19:25:02

data segment
carryout db 0dh,0ah,' carry out!','$'
crlfmsg db 0dh,0ah,'$'
data ends

stacks segment stack
dw 20 dup(?)
top label word
stacks ends

code segment
    assume cs:code,ss:stacks,ds:data
main proc far

    mov ax,data
    mov ds,ax

    mov ax,stacks
    mov ss,ax
    lea sp,top


    mov cx,5;max number 65535
    xor bx,bx
l1: mov ah,01h
    int 21h

    cmp al,0dh
    je input

    cmp al,30h
    jb l1
    cmp al,39h
    ja l1

    and ax,1111b
    xchg ax,bx
    mov di,10
    mul di
    jc carry
    add bx,ax
    jc carry

    loop l1

carry:
    lea dx,carryout
    mov ah,09h
    int 21h
    jmp exit    

input:
    call hex
    call Four
    jmp exit



Hex proc near
    ;in bx !
    mov ch,4
l2: 
    mov cl,4
    rol bx,cl
    mov dl,bl
    and dl,1111b
    add dl,30h

    cmp dl,39h
    jbe l3
    add dl,7h
l3:
    mov ah,02h
    int 21h

    dec ch
    jnz l2


    call crlf
ret 
Hex endp

Four proc near

    mov ch,8
l4: mov cl,2
    rol bx,cl
    mov dl,bl
    and dl,11b
    add dl,30h
    mov ah,02h
    int 21h

    dec ch
    jnz l4

    call crlf
ret
Four endp

crlf proc near
    lea dx,crlfmsg
    mov ah,09h
    int 21h

ret
crlf endp


exit:
    mov ah,4ch
    int 21h

main endp
code ends
end main 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值