Re: A86: string decimal -> HL


[Prev][Next][Index][Thread]

Re: A86: string decimal -> HL




Try this (not tested, obviously!):

Str_to_hl:
 ld hl,0		; clear out hl
 ld b,0		; clear high byte
loop:
 call Read_byte	; get the next byte
 sub 48		; calc num value of the char ('0' = 48)
 cp 10			; is it greater than 9?
 ret nc		; if so, then we're done
 ld c,a		; save value
 sla l			; hl * 2
 rl h			; ...
 ld de,hl		; save hl * 2
 sla l			; hl * 4
 rl h			; ...
 sla l			; hl * 8
 rl h			; ...
 add hl,de		; (hl * 8) + (hl * 2) = hl * 10
 add hl,bc		; add value
 jr Str_to_hl		; loop through the entire string

I hope this helps!


At 07:40 PM 8/8/98 PDT, you wrote:
>
>Hello all you Z80 hackers...
>
>Heres the request:
>
>I need a routine that takes a string containing a decimal value, and 
>store that value in HL. Access to the string is limited to one character 
>at a time, via a routine called Read_byte, which stores the next 
>character in the A register.
>
>Ok, to reiderate and expand.
>
>You can use
>Read_byte : A contains next byte in string, updating pointer to string, 
>etc.
>Peek_at_byte : A contains next byte in string, not updating pointer.
>
>I have already made the hex version of this... though it needs to be 
>re-written too. You can tell when you are at the end of the decimal 
>number because you will run into a character that isn't 0-9 :)
>
>If anyone is up to this challeng I would really appreaciate it.
>
>--awwaiid
>Retupmoc7@hotmail.com
>
>
>______________________________________________________
>Get Your Private, Free Email at http://www.hotmail.com
>

--
David Phillips
mailto:electrum@tfs.net
ICQ: 13811951
AOL/AIM: electrum32


References: