[TI ASM] converting hex to number?

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

[TI ASM] converting hex to number?

Post by King Harold »

In basic we can do this:
Repeat A<16
A-16->A
End

i need to make a 16bit hex value into a 5 digit number
it can be done, and in basic i have, but in assembly it gets all confusing
please help?
(after converting it, the 5 digits are supposed to be ascii values of largefont numbers, which should be stored in a 5 byte string somewhere, if it matters anything to the conversion.. (optimisations maybe))
Kalimero
Regular Member
Posts: 130
Joined: Fri 17 Dec, 2004 1:47 pm

Post by Kalimero »

Maybe you can use bcall(_dispHL). You can also have a look at http://baze.au.com/misc/z80bits.html#5.1.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Ofcourse i could use disp hl, but i dont want to disp hl, i want to put it into to string to load as a name for an AppVar
that z80 bits thing looks like it should work though
CompWiz
Calc King
Posts: 1950
Joined: Thu 13 Oct, 2005 1:54 pm
Location: UB

Post by CompWiz »

why not go for the completely inefficient method of having your asm program create your basic program to convert it, and then use the converted value and delete the basic program. :twisted:
In Memory of the Maxcoderz Trophy Image
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

well i Could do that.....
but its worth messing around with the code for a month or more to come up with the asm alternative (a good method has allready been provided by chickendude)
User avatar
qarnos
Maxcoderz Staff
Posts: 227
Joined: Thu 01 Dec, 2005 9:04 am
Location: Melbourne, Australia

Post by qarnos »

King Harold wrote:well i Could do that.....
but its worth messing around with the code for a month or more to come up with the asm alternative (a good method has allready been provided by chickendude)
If you want to do it without a bcall, or if you need the actual text, you can use this:

Code: Select all

NToS:       ld      bc, -10000
            call    _getDigit
            ld      bc, -1000
            call    _getDigit
            ld      bc, -100
            call    _getDigit
            ld      bc, -10
            call    _getDigit
            ld      a, l
            add     a, 48
            ld      (de), a
            inc     de
            xor     a
            ld      (de), a
            ret            
_getDigit:  ld      a, 47
_getDigitLp:inc     a
            add     hl, bc
            jp      c, _getDigitLp
            sbc     hl, bc
            ld      (de), a
            inc     de
            ret
This code will take a number in HL, and an output address in DE. When it returns, DE will point at the terminating NULL. All other registers are clobbered and the result has leading zeros if the number was < 10,000.
Post Reply