Anyone know assembler?

Apr 5, 2000
13,256
1
0
I was doing a program (due on Friday though) and basically we need to display on screen the contents of the general purpose registers ax, bx, cx, and dx in HEX format. I can get it to work when printing any number from 0-7, but it will not work for numbers 8-F.

Basically I'm multipling AX (what I'm printing out) by 16 to move the info into DL, then adding 30h or 37h depending on the value of DL. My code is:

******************************

PHex PROC
push ax
push bx
push cx
push dx ; Save contents of general purpose registers

mov ax, A

mov cx, 4 ; Initialize loop counter
loopit:
imul F
cmp dl, 0Ah
jl Add30 ; Multiply ax by 16, compare dl with 10. If less than goto Add30
add dl, 37h ; otherwise add 37h (55) and jump to done
jmp done
Add30:
add dl, 30h ; If dl < 10 add 30h (48)
done:
push ax
mov ah, 02h
int 21h ; save content of ax on stack, print dl, pop off ax, loop if
pop ax ; cx > 0
loop loopit

pop dx
pop cx
pop bx ; restore contents of general purpose registers
pop ax

PHex ENDP

********************************

My problem is that if any value between 8-F (F = 15 in hex), take 8 for example. It prints out ( instead of an 8. A 13 prints out - and a F prints out a /

Any number between 0-7 works fine. I calculated this in ASCII, and 8 + 32 = 40, and ( = 40 in ASCII. (If the code worked like it was supposed to, it was supposed to have added 48 instead of 32) 0-7 adds 48, but anything between 8-F only adds 32, which is 20H. Anyone see my problem?

I would ask the teacher for help but he doesn't like me :( Thanks for the help in advance!
 

poop

Senior member
Oct 21, 1999
827
0
0
Um, you should probably mention what CPU/MCU you are using. I can only assume x86. If it were MIPS or motorolla 68HC11 or PIC, I could be more of assistance.
 
Apr 5, 2000
13,256
1
0
Oops sorry. Yes, the x86. (Intel based cpu's, limited to I think the 8086 instruction set)

We havent quite learned shifts yet so I don't want to use it (with shifting that code would be half the size)