Message board for the users of flat assembler.
> Windows > mod operator help
I have been looking for a way to get the remainder of a idiv operation in my program. unfortunately where ever I try to use the idiv or div operations my program crashes when it finishes the thread in which it is used. I read that mod was a valid operator in fasm but have found relatively few examples of it's use and my tries have failed(probably in wrong context). It would be helpful for me if someone could write a macro or proc that could do
eax=eax mod inputnumber
that works inside a thread. in case it matters my thread declaration is
mov eax,ThreadProc invoke CreateThread,NULL,0,eax,NULL,NORMAL_PRIORITY_CLASS,[ThreadId] invoke CloseHandle,eax
|02 Aug 2008, 17:21||
a thread has its own stack and you have to assume registers are different in the thread i mean, if you didnt set them IN THE THREAD you cannot rely on their values.
Generally the problem occurs with ebp.
Prototype for CreateThread:
HANDLE WINAPI CreateThread(
__in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,
__in SIZE_T dwStackSize,
__in LPTHREAD_START_ROUTINE lpStartAddress,
__in_opt LPVOID lpParameter,
__in DWORD dwCreationFlags,
__out_opt LPDWORD lpThreadId
If i read well, your [ThreadId] is probably not correct if you expect the thread id to be returned in the dword place in memory called ThreadId. Don't use 
|02 Aug 2008, 19:36||
Example of MOD programming
Routine to compute (seed*A) MOD M (32 bits numbers)
after execution eax contains this value.
prototype: int rand(int)
M equ 7fffffffh ;2^31-1
seed equ dword [ebp+8]
A equ 16807
push edx ebx
xor edx,edx ;clear edx
mul seed ;edx:eax<-seed*A
div ebx ;edx<-(seed*A) mod M
pop ebx edx
ret 4 ;don't forget it!
Routine used in a Linear congruential generator.
|02 Aug 2008, 19:51||
I fixed the brackets,didn't change anything since I wasn't using that handle(just following a tutorial).think div may be working, it just causes a crash on thread exit. replaced div with a subtraction loop and it runs without crashing.
|03 Aug 2008, 13:36||
[ Post removed by author. ]
Last edited by Yardman on 04 Apr 2012, 03:23; edited 1 time in total
|03 Aug 2008, 17:28||
that proc worked for me I will have to analyze later what I was doing wrong.
|04 Aug 2008, 01:21||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.
Website powered by rwasa.