要实现从键盘输入四个数字,然后转化成二进制输出,再转化成十六进制输出。
程序用emu8086运行没问题,但生成exe文件后运行就不对了。
dseg segment
enter db 4 dup(?)
aa dw 000ah
sum dw 0000h
hhh db 4 dup(?)
dseg ends
cseg segment
assume cs:cseg,ds:dseg
main proc far
push ds
mov ax,0000h
push ax
mov bx,0000h
mov cx,0000h
mov ax,offset dseg
mov ds,ax
lea di,enter
lea si,hhh
start:mov ah,01h
int 21h
mov [di],al
inc di
inc cl
cmp cl,04h
jnz start 向enter传值,传4次
sub di,04h 首地址复位
chang:mov ax,0000h
mov al,[di]
add ax,sum
sub ax,30h
cmp cl,07h {[(a*10)+b]*10+c*10}+d=abcd
jz unmul
mul aa
unmul:mov sum,ax 最后结果传给sum
inc cl
inc di
cmp cl,08h
jnz chang
mov cl,00h
mov bx,sum
next: shl bx,1h
jc print
mov dl,30h
mov ah,02h
int 21h
jmp re
print:mov dl,31h 左移,有进位打1没进位打0
mov ah,02h
int 21h
re: inc cl
cmp cl,10h
jnz next
mov cx,00h 逻辑左移、右移,并转换成ASCII码,存入hhh中
mov cl,04h
mov ax,sum
shr ah,cl
mov ch,ah
cmp ch,0ah
jns t1
add ch,30h
t11: mov [si],ch
inc si
mov ax,sum
shl ah,cl
shr ah,cl
mov ch,ah
cmp ch,0ah
jns t2
add ch,30h
t22: mov [si],ch
inc si
mov ax,sum
shr al,cl
mov ch,al
cmp ch,0ah
jns t3
add ch,30h
t33: mov [si],ch
inc si
mov ax,sum
shl al,cl
shr al,cl
mov ch,al
cmp ch,0ah
jns t4
add ch,30h
t44: mov [si],ch
sub si,03h
mov cl,00h
jmp en
t1: add ch,37h
jmp t11
t2: add ch,37h
jmp t22
t3: add ch,37h
jmp t33
t4: add ch,37h
jmp t44
en: mov ah,2h
mov dl,[si]
int 21h
inc cl
inc si
cmp cl,4h
jnz en
mov ah,4ch
int 21h
main endp
cseg ends
end main