从键盘输入十进制数转换成为十六进制数并显示
下面是我的代码,可是运行结果不对,麻烦各位高手指点~~补充:具体描述一下程序中堆栈的过程,我不太清楚我的堆栈是否成功了~~谢谢
data segment
s0 db 0dh,0ah,"$"
s1 db "Please input a dec num: $"
s2 db "The hex num is: $"
n equ 10
buf db n+1
count db 0
string db n+1 dup('$')
data ends
stack segment stack
db 100 dup(?)
stack ends
code segment
assume cs:code,ds:data,ss:stack
start:
mov ax, data
mov ds, ax
mov ah, 09h
mov dx, offset s1
int 21h
mov ah, 0ah
lea dx, buf
int 21h
mov ah, 09h
mov dx, offset s0
int 21h
mov ah, 09h
mov dx, offset s2
int 21h
lea si, string
mov ax, 10000
push ax
mov ax, 1000
push ax
mov ax, 100
push ax
mov ax, 10
push ax
mov ax, 1
push ax
mov bx, 0
mov cx, 0
mov dx, 0
mov bh, count
L:
mov bl, [si+count-1]
and bl, 0fh
pop ax
mul bl
mov bl, 8
left1:
sal dx, 1
dec bl
cmp bl, 0
jnz left1
add dx, ax
mov cx, dx
dec bh
cmp bh, 0
jnz L
mov dx, cx
mov cx, 0
mov bx, 0
mov cl, 4
tohex:
mov bl, 0
mov al, 4
left2:
shl dx, 1
rcl bl, 1
dec al
jnz left2
push dx
cmp bl, 09h
jbe asc1
asc2:
sub bl, 9
or bl, 40h
mov ah, 02h
mov dl, bl
int 21h
pop dx
loop tohex
jmp end1
asc1:
or bl, 30h
mov ah, 02h
mov dx, 0
mov dl, bl
int 21h
pop dx
loop tohex
jmp end1
end1:
mov ah, 4ch
int 21h
code ends
end start