flat assembler
Message board for the users of flat assembler.

Index > Main > Division...

Author
Thread Post new topic Reply to topic
manfred



Joined: 28 Feb 2009
Posts: 43
Location: Racibórz, Poland
manfred
Hi all (it's my first post)!

What should I use when I need division? DIV is too slow, and SHR isn't versatile... I didn't found anything, but probably I don't know what I must search for...

_________________
Sorry for my English...
Post 28 Feb 2009, 21:33
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
What for? For vast majority of purposes, DIV is fast enough.
Post 28 Feb 2009, 22:46
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
Try this tool: http://www.wasm.ru/baixado.php?mode=tool&id=203
If you need some more info, you may find this thread interesting:
http://www.asmcommunity.net/board/index.php?topic=21308.0
(you can find me participating there)
Post 28 Feb 2009, 23:14
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Note that The Svin's tool may not work for some numbers.

This code comes from a PM I've sent to a member of this forum to avoid pollution of a thread of that moment (I think):
Code:
include 'win32ax.inc'

start:
            mov ecx, $FFFFFFFF ; -1 ; Only value in which it fails (uncomment "-1" and the program will end successfully)
            mov edi, 7

            align 16
            place:

MagicNumber = 2454267026 ; 7
mov eax,ecx
mov edx, MagicNumber
inc eax
mul edx
SHR edx, 2

                mov esi, edx

                mov eax, ecx
                xor edx, edx
                div edi

                cmp eax, esi
                jne fail

                sub ecx, 1
                jnc place

            invoke MessageBox, 0, "all just fine!", "OK", 0
exit:
            invoke ExitProcess,0

fail:
  cinvoke wsprintf, buff, fmt, ecx, esi, eax
  invoke  MessageBox, 0, buff, "ERROR!", 0
  jmp     exit

fmt db "%u div 7 = %u but actually it is %u", 0
buff rb 256


.end start    


This doesn't happen with any number and I don't know if this is the only divisor that it is flawed or if there are more.
Post 01 Mar 2009, 02:42
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
Yes, for a value near to 2^32 there may occur an overflow in some cases - see my analysis in the other thread. But for a significantly smaller values this should be a safe method.
Post 01 Mar 2009, 09:36
View user's profile Send private message Visit poster's website Reply with quote
manfred



Joined: 28 Feb 2009
Posts: 43
Location: Racibórz, Poland
manfred
Tomasz Grysztar wrote:
Try this tool: http://www.wasm.ru/baixado.php?mode=tool&id=203
If you need some more info, you may find this thread interesting:
http://www.asmcommunity.net/board/index.php?topic=21308.0


This is great, thanks!

_________________
Sorry for my English...
Post 01 Mar 2009, 09:47
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Tomasz Grysztar wrote:
Try this tool: http://www.wasm.ru/baixado.php?mode=tool&id=203


Interesting, OTOH not FASM ...

Quote:
If you need some more info, you may find this thread interesting:
http://www.asmcommunity.net/board/index.php?topic=21308.0
(you can find me participating there)


Oops, you are active in other forums than yours also Laughing

I'll drop a deeper look into it and test maybe Smile
Post 01 Mar 2009, 12:05
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.