汇编语言: 试编写一段程序,从键盘接收一个-32768-32767 间的十进制有符号数,并在终端上 显示与它等值的二进制数。

**
更多习题答案见

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

**

试编写一段程序,从键盘接收一个-32768-32767 间的十进制有符号数,并在终端上 显示与它等值的二进制数。

data segment
carryoutmsg db 0dh,0ah,'carry out!','$'
crlf 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

    xor di,di
    xor bx,bx   
    mov cx,5

input:
    mov ah,01h
    int 21h

    cmp al,0dh
    je show

    cmp al,'-'
    jne nosign

    cmp cx,5
    jne input
    mov di,1

nosign:
    cmp al,30h
    jb input
    cmp al,39h
    ja input

    and ax,1111b
    xchg bx,ax
    mov dx,10
    mul dx
    add ax,8000h
    jc carryout
    add bx,ax
    jc carryout
    sub bx,8000h
    dec cx
    cmp cx,0
    jne input   
    jmp show

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

show:
    lea dx,crlf
    mov ah,09h
    int 21h

    cmp di,1
    jne l2
    neg bx

l2: mov cx,16
l3: rol bx,1
    mov dl,bl
    and dl,1
    add dl,30h
    mov ah,02h
    int 21h
    loop l3

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、付费专栏及课程。

余额充值