Re: A86: Seperating strings...?


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

Re: A86: Seperating strings...?




In a message dated 9/19/97 7:09:35 PM, you wrote:

>DoubleGate wrote:
>
>> 
>
>> To anyone and everyone,
>
>> 
>
>>         First of all..  let me say hello to everyone..  I've been reading
this
>> newslist for awhile now, but only just got up enough intelligence on the
>> subject to feel worthy to post.  **grin**
>>         Ok my question is:  Is it possible to seperate the numerals in a
larger
>> number..  Like say I add 424 and 500..  I get 924.  Is there any way to
>> seperate the 9, 2, and 4?  In BASIC or assembly...  I dont want to give
>> every numeral a varible..  I just want to be able to seperate the numerals
>> after a normal operation..  Possible?
>
>There is a ROM call that does exactly what you want. call $4044
>
>will divide HL with 10 and put the remainder in A.
>
>
>
> ld hl,424
> ld de,500
> add hl,de  ; HL=924
> call $4044
> ; A = 4
> call $4044
> ; A = 2
> call $4044
> ; A = 9
>
>
>
>-- 
>
>Jimmy Mardell

You can do something similar in BASIC using mods.

924->A
for(x,1,3)
mod(A,10)->B
A/10->A
iPart A->A
end

After that the first time B=4, then B=2, last B=9.  You can also incorporate
that into a for loop.  Antother way would be:

924->A
for(x,1,3)
A/10->A
iPart (fPart (A*10))->B
end

Same results.