Good evening, how are you doing? I was wondering could help me out with on how I would go about this problem. What I want to do is have a user enter two hex numbers in hex form then add them up and output the hex value. Anyone have any ideas on how to start this or how this should be done. Thanks for all your help
Posted on 2004-10-31 14:25:16 by skull_block
Actually I do have it working so far the issue I am having is when I enter letters for the hex value I am not getting the correct decimal value. Here is my code to get the hex number entered let me know if you see anything that I am not seeing.
push bx

push cx
push dx
mov bx,0
mov cx, 1
mov Sign ,0
_GetCh
cmp al,'-'
jne AfterRead2
mov Sign,'-'

ReadLoop2:
_GetCh

AfterRead2:
mov pow16,16
cmp al,'0'
jb Done2
;cmp al,'9'
;ja Done2
sub al, '0'
mov ah, 0
xchg ax,bx
mul cx
mul pow16
add ax,bx
xchg ax,bx
sub ax,ax

jmp ReadLoop2
Done2:
cmp al,13
jne NoLF2
_PutCh 10
NoLF2:
cmp Sign, '-'
jne Positive2
neg bx
Positive2:
mov ax,bx
pop dx
pop cx
pop bx
ret
GETHEXI ENDP

Thanks
Posted on 2004-10-31 15:51:38 by skull_block
* convert the hex ascii representation to hex value ( htodw )
* add the values
* convert back to ascii hex representation
Posted on 2004-10-31 16:13:48 by arafel
PUTHEXI  PROC

push ax
push bx
push cx
push dx
cmp ax, -32768
jne TryNeg2
_PutStr M32768
jmp Done3

TryNeg2:
cmp ax,0
jge NotNeg2
mov bx,ax
neg bx
_PutCh '-'
mov ax,bx

NotNeg2:
mov cx,0
mov bx,16

PushDigs2:
sub dx,dx
div bx
add dl, '0'
push dx
inc cx
cmp ax, 0
jne PushDigs2

PopDigs2:
pop dx
_PutCh dl
dec cx
jnz PopDigs2

Done3:
pop dx
pop cx
pop bx
pop ax
PUTHEXI ENDP


This is my code to display the hex value on the screen. It works but it displays the ASCII value not the hex value of the letter. ex 63 would display as 3? instead of 3F why is it doing that. Thanks for the help
Posted on 2004-10-31 20:01:12 by skull_block
a more clean way is to use sbb and das instructions. this will also resolve problem with not printing low nibble in your routine.

	mov bl, al


shr al, 4
cmp al, 10
sbb al, 105
das
_PutCh al

mov al, bl

and al, 00001111b
cmp al, 10
sbb al, 105
das
_PutCh al
Posted on 2004-11-01 16:54:03 by arafel
You know what thanks for the help on the put hex but I think my issue is the gethex this is my code but it isn't displaying the hex value when I use my get hex and call put hex it displays a decimal value. But I know my puthex works because i have tested it against my get dec. What is missing?
 push bx

push cx
push dx
mov bx,0
mov cx, 1
mov Sign ,0
_GetCh
cmp al,'-'
jne AfterRead2
mov Sign,'-'

ReadLoop2:
_GetCh

AfterRead2:
mov pow16,16
cmp al,'0'
jb Done2
; cmp al,'9'
; ja Done2
sub al, '0'
mov ah, 0
xchg ax,bx
mul cx
mul pow16
add ax,bx
xchg ax,bx
sub ax,ax

jmp ReadLoop2
Done2:
cmp al,13
jne NoLF2
_PutCh 10
NoLF2:
cmp Sign, '-'
jne Positive2
neg bx
Positive2:
mov ax,bx
pop dx
pop cx
pop bx
ret
Posted on 2004-11-02 19:32:15 by skull_block