dx 汇编dec_[汇编] 十进制和十六进制数之间的转换

; multi-segment executable file template.

data segment

; add your data here!num dw0string1 db'please choose 1 (dec->hex) or 2 (hex->dec)]:$'inputDec db'please input a Dec number :$'inputHex db'please input a Hex number :$'ends

stack segment

dw128 dup(0)

ends

code segment

start:

;setsegment registers:

mov ax, data

mov ds, ax

mov es, ax

;-------------选择模式------------------model:

lea dx, string1

mov ah,9

int21h

mov ah,1

int21h

sub al,30h

cmp al,1mov cx,10;乘10

jz option1

call CRLF

cmp al,2mov cx,16jz option2

call CRLF

jmp model

;----------------------------------------;***********十进制转十六进制*****************;-----------输入一个十进制数-------------option1:

call CRLF

lea dx,inputDec

mov ah,9

int21h

rotate1:

mov ah,1

int21h

cmp al,0dh ;回车结束十进制数的输入

jz DectoHex

sub al,30h

cbw

push ax

mov ax,bx

mul cx

mov bx,ax

pop ax

add bx,ax ;输入结果保存在bx中

jmp rotate1

;-----------------------------------------;---------开始转换(10->16)-------------DectoHex:

call CRLF

mov ch,4rotatecur:

mov cl,4rol bx,cl

mov al,bl

and al,0fh

add al,30h

cmp al,3ah

jl print1

add al,7h

print1:

mov dl,al

mov ah,2

int21h

dec ch

jnz rotatecur

call exit

;**************十六进制转十进制*******************;-------------输入一个十六进制数------------------option2:

call CRLF

lea dx,inputHex

mov ah,9

int21h

rotate2:

mov ah,1

int21h

cmp al,0dh ;回车结束十六进制数的输入

jz HextoDec

sub al,30h

cmp al,9jg Other

L:

cbw

push ax

mov ax,num

mul cx

mov num,ax

pop ax

add num,ax ; 输入结果保存在num中

jmp rotate2

Other:

sub al,7h

jmp L

HextoDec:

call CRLF

mov cx,1000;----------重复的输出代码。。。-----mov ax, num

mov dx,0div cx

mov num, dx

mov dl, al

add dl,30h

mov ah,02hint21h

;--------------------mov cx,100;----------mov ax, num

mov dx,0div cx

mov num, dx

mov dl, al

add dl,30h

mov ah,02hint21h

;----------mov cx,10;----------mov ax, num

mov dx,0div cx

mov num, dx

mov dl, al

add dl,30h

mov ah,02hint21h

;----------mov cx,1;----------mov ax, num

mov dx,0div cx

mov num, dx

mov dl, al

add dl,30h

mov ah,02hint21h

;----------call exit

;----------取每一位------------------;-----------------------------------;--------回车换行------------------CRLF proc near

push ax

push dx

pushf

mov dl,0dh;回车

mov ah,2

int21h

mov dl,0ah;换行

mov ah,2

int21h

popf

pop dx

pop ax

ret

CRLF endp

;-----------------------------------------;-----------------退出---------------------exit proc

mov ax, 4c00h ; exit to operating system.int21h

exit endp

;------------------------------------------ends

end start ;set entry point and stop the assembler.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值