Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Hex. to Decimal

Status
Not open for further replies.

zskater

Programmer
Apr 14, 2001
22
GB
I am studying computing science at university and i am having problems with the following homework
I'm hoping someone will be able to help me out.


HOMEWORK
Develop an emmbedded intel 8086 assembler program in stages to solve the following problem

Convert a string containing an unsigned integer as a sequence of hexidecimal character digits to another string containing the corresponding decimal character digits within the assembler, without using any logical operations (AND,OR,XOR,shift), without using multiplication or division operations and without using a straight sequence of simple 4 repeated ADD operations to achieve multiplication.
The Pascal section will only input the original string and print the result.
(assume that the maximum hex. input number is 7FFF. use only 8-bit and 16-bit registers, except for the 32-bit string address register.)

You may find it helpful to use internal procedure calls in the assembler, which jump to a section of code with a label and which returns to the assembler statment after the call

CALL @POINT {call procedure POINT}
....
@POINT NOP {start of procedure}
....
RET {return from procedure}

I have 3 days left before I have to hand it in.
Cheers Steve
 
Ok. I don't have time to think of a better solution (Any solution is better than this one), but it is better than nothing, so here it is:

START:
MOV CX,0FFFFh ;the number to turn to Decimal
MOV AX,0
MOV BX,0
MOV DL,0
INC_LOOP:
INC AL ;AL is the first digit
CMP AL,0Ah ;Has it reached 10 yet?
JNE CONTINUE ;No, continue.
MOV AL,0 ;Yes, empty it
INC AH ;AH is the second digit
CMP AH,0Ah ;Has it reached 10 yet?
JNE CONTINUE ;No, continue ...
MOV AH,0
INC BL ;BL is the third digit
CMP BL,0Ah
JNE CONTINUE
MOV BL,0
INC BH ;BH is the forth digit
CMP BH,0Ah
MOV BH,0
INC DL ;DL is the fifth digit

CONTINUE:
LOOP INC_LOOP

Now you will have every Decimal digit in a different 8-bit register. Making the string from here shouldn't be a problem.

Hope you find a better solution, and if you do, or if your teacher shows you one, please tell me about it.
 
I would suggest to use this algorithm:
- Check how many 10 thousands your number has

XOR CX,CX
@loop_TT :
CMP Number, 3e8h
jb @TT_DONE
INC CX
JMP @loop_TT
@TT_DONE :

; {Now you have to display value of CX, if it is more than Ah, then display '1', then SUB CX,0Ah , display the rest}

and this algo should do the same for thousands,hundreds, tens and the last display as it appears.

Best Regards,

aphrodita@mail.krovatka.ru {uiuc rules}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top