flat assembler
Message board for the users of flat assembler.

Index > Main > Use and for divide 10?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 05 May 2020, 17:45
In 1996 i see on zx spectrum example divide 10 int number 99999 for print asc2 string.

And i want use and. And not use div


Last edited by Roman on 06 May 2020, 11:01; edited 1 time in total
Post 05 May 2020, 17:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20447
Location: In your JS exploiting you and your system
revolution 06 May 2020, 04:13
99999 and 9999 = 1551
The answer of 9999 is not possible by using and alone.

xor can do it:
99999 xor 106896 = 9999

It also multiplies by 10:
9999 xor 106896 = 99999
Post 06 May 2020, 04:13
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 07 May 2020, 10:25
In packman game i see convert integer to asc2 where use asm comand And
And not use many calls.
But i found this code
Code:
16-bit Integer to ASCII (decimal)
Input: HL = number to convert, DE = location of ASCII string
Output: ASCII string at (DE)

Num2Dec:
        ld      bc,-10000
        call    Num1
        ld      bc,-1000
        call    Num1
        ld      bc,-100
        call    Num1
        ld      c,-10
        call    Num1
        ld      c,b

Num1:
        ld      a,'0'-1
Num2:   inc     a
        add     hl,bc
        jr      c,Num2 ;this carry flag. JMP if c=1
        sbc     hl,bc

        ld      [de],a
        inc     de
        ret
    


Last edited by Roman on 07 May 2020, 10:30; edited 1 time in total
Post 07 May 2020, 10:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20447
Location: In your JS exploiting you and your system
revolution 07 May 2020, 10:30
That is using add, not and.

Is is subtracting multiples of 10^n and counting the loops.

IMO it gets unwieldy for 32-bit numbers and quite ugly for 64-bit numbers, especially if you want to do leading zero suppression.
Post 07 May 2020, 10:30
View user's profile Send private message Visit poster's website Reply with quote
st



Joined: 12 Jul 2019
Posts: 49
Location: Russia
st 16 May 2020, 08:01
Z80 does not support div nor mul, that is why such routines were common for it. On x86 it is more appropriate to use multiplication with magic numbers https://board.flatassembler.net/topic.php?t=20099

Also please take a look at Magic Divider by The_Svin
Post 16 May 2020, 08:01
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 20 May 2020, 08:56
aam is the instruction you're searching for.

after aam:
ah = al/10
al = al%10
Post 20 May 2020, 08:56
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.