INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Convert Hex. to Decimal

## Convert Hex. to Decimal

(OP)
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

### RE: Convert Hex. to Decimal

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.

### RE: Convert Hex. to Decimal

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}
http://www.hellforge.org

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!