Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Having trouble with Program converting Dec. to Hexadecimal

I'm down to my last straw. :~(



I'm am having such a hard time with Assembly Language. I need to write a program that takes in a Decimal # from the user, then Output's its Hexadecimal value.



I'm stumped. This is what I got ....it used to compile when i had the GETHEX Proc inside Main Proc ...but now it doesent since I moved it out.



I think im terribly lost. Any and all help is much appreciated. Thanks.



.MODEL SMALL

.STACK 100h

.DATA

PROMPT1 DB "Enter a decimal number: " , '$'

PROMPT2 DB 'Hex Value: '

temp DB ?,?,?,?

L_FEED DB 13, 10, '$'



.CODE



START:



main PROC

mov ax, @data

mov ds, ax



mov ah, 9 ; prompt for the input

mov dx, OFFSET PROMPT1

int 21h





call GETHEX



mov bl, al



mov ah, 9

mov dx, OFFSET L_FEED ; print a blank line

int 21h





mov ah, 9 ; print blank line and exit

mov dx, OFFSET L_FEED

int 21h

mov ah, 4ch

int 21h

main ENDP

END START



GETHEX PROC

mov ah, 0ah ; get the input

int 21h

cmp al, 41h ; compare first char with 41h

jge LOOP1 ; jump to LOOP1 if greater or equal to 41h

sub al, 30h ; al= al-30

jmp LOOP2

LOOP1:

sub al, 37h

LOOP2:

mov temp, al

push cx

mov cl, 4

shl al, cl

mov temp, al





mov ah, 0ah ; get the second input

int 21h

cmp al, 41h

jge LOOP3

sub al, 30h

jmp LOOP4

LOOP3:

sub al, 37h

LOOP4:

mov temp+1, al

mov al, temp

or al, temp+1

mov bh, al

mov bl, al

pop cx

ret

GETHEX ENDP










URL:http://www.toadie.lovesmusic.com

Comments

  • As far as compilation goes, if you move the END START to the end of the program, TASM will compile it without complaint.



    The program inputs fine, but the output appears broken.



    --MW


Sign In or Register to comment.