Page 1 of 1

[TI ASM] converting hex to number?

Posted: Tue 08 Aug, 2006 9:26 am
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))

Posted: Tue 08 Aug, 2006 9:55 am
by Kalimero
Maybe you can use bcall(_dispHL). You can also have a look at http://baze.au.com/misc/z80bits.html#5.1.

Posted: Tue 08 Aug, 2006 10:09 am
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

Posted: Tue 08 Aug, 2006 3:17 pm
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:

Posted: Tue 08 Aug, 2006 3:33 pm
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)

Posted: Thu 17 Aug, 2006 10:41 am
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.