Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Hex to Hex Representation of Decimal in ASM

Status
Not open for further replies.

SavEagle

Newbie level 2
Joined
May 5, 2009
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,296
hex representation

Hi there. I haven't the foggiest on the best way to do this in ASM. What I need is to convert a hex number to the hex representation of the decimal number. For example:

Start with:
2Eh (It iss equal to 46d)

End with:
46h

I need to end up with the byte in hex because of how I send the byte to the screen by converting each nibble into its ascii.

If theres a simpler way to send a hex value's decimal equivalent to the display I'd be glad to hear that as well!

Thanks in advance!
 

hex representation of €

ASM for what cpu?

To convert Binary to BCD this is a double-dabble algorithm, it only requires N shifts for an N bit number, but more overhead in tracking adjustments.
**broken link removed**
 

what is the decimal of 2eh

Hai

Normally decimal values doesnt end with d, you can simply specify 46 in decimel.

Only hex and binary should be coded with h and b at the end respectively.

You can use anything with asm, the compiler will handle it. dont worry about it.

Regards
Nandhu

Note: This is common method, check out your specific compiler manual for detailed description
 

hex representation of decimal

I believe SavEagle is trying to convert 2Eh (or 46d) into 46h (or 70d) which is a Binary to BCD conversion.
 

number 99 in hex

Yeah. I'd need the same process to convert 33h (51d) to 51h.
 

2eh in hex

I don't know what cpu your writing ASM for.

If your number is always under 100d, then the Double-Dabble can be reduced to
Code:
 PSEUDOCODE
Result = 0
IF Number>99 THEN
 Number = 0 // Clear on Error
ENDIF

LSL Number // Number Shift Left into Carry
RLC Result // Result Rotate Left through Carry
LSL Number
RLC Result
DO
 IF (Result & 0Fh) > 4 THEN // if >=5 then adjust
    Result = Result + 3 
 ENDIF
 LSL Number
 RLC Result
UNTIL Number = 0
This algorithm uses no multiply or divide, just simple add and shifts found on almost all cpu's. The main loop will execute 1 to 5 times maximum.

Some low end CPU's dont have multiply and divide, and if they do execution times are slow.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top