flat assembler
Message board for the users of flat assembler.

 Index > Main > Use and for divide 10?
Author
Roman

Joined: 21 Apr 2012
Posts: 825
Roman
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
05 May 2020, 17:45
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17714
revolution
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
06 May 2020, 04:13
Roman

Joined: 21 Apr 2012
Posts: 825
Roman
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
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
07 May 2020, 10:25
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17714
revolution
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.
07 May 2020, 10:30
st

Joined: 12 Jul 2019
Posts: 45
Location: Russia
st
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
16 May 2020, 08:01
edfed

Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
aam is the instruction you're searching for.

after aam:
ah = al/10
al = al%10
20 May 2020, 08:56
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum