Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Translating Lua to ASM.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Mar 25, 2016 7:06 pm    Post subject: Translating Lua to ASM. Reply with quote

Please take a look at the following Lua code:
Code:

math.randomseed(os.time())
local x = math.random(0,10)
local y = math.random(0,10)
while x == y do y = math.random(0,10) end


How to write a piece of ASM code that can achieve the same result? I am really new to ASM language (X86).

Thanks in advance.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4709

PostPosted: Fri Mar 25, 2016 9:43 pm    Post subject: Reply with quote

Assuming the process has the msvcrt library loaded, you can call srand and rand from that dll. Both should use the cdecl calling convention. You can call GetTickCount from kernel32 to pass to srand. Use the div instruction and get the remainder from EDX to limit it to an integer from 0 to 10.

Google around for examples. Wikipedia has examples on the cdecl calling convention. There should be a few CE topics dealing with rand (here is one you made).

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Mar 25, 2016 10:32 pm    Post subject: Reply with quote

ParkourPenguin wrote:
Assuming the process has the msvcrt library loaded, you can call srand and rand from that dll. Both should use the cdecl calling convention. You can call GetTickCount from kernel32 to pass to srand. Use the div instruction and get the remainder from EDX to limit it to an integer from 0 to 10.

Google around for examples. Wikipedia has examples on the cdecl calling convention. There should be a few CE topics dealing with rand (here is one you made).


Penguin, it's you again, my friend. Thank you as usual. I have two problem today, one is about declaring variables, the other one is the use of srand. You helped me on both issues. Very Happy Thanks again.
BTW, I have found this:
Code:

//Only once in a module {
  call getTickCount
  push eax
  call srand
//}

// as much as required
  call rand
// a new random number in eax
 call rand
// a new random number in eax
....
// div (max-min)
// add edx,min
// now min < edx < max


Is this what you meant? I can define the range by giving max and min values, right?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4709

PostPosted: Fri Mar 25, 2016 11:08 pm    Post subject: Reply with quote

I give a brief explanation and an example of this here. Look up what the div instruction does to get a better understanding of why that code works (link to a reference). If you need more help, just ask.
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Sat Mar 26, 2016 6:55 am    Post subject: Reply with quote

ParkourPenguin wrote:
I give a brief explanation and an example of this here. Look up what the div instruction does to get a better understanding of why that code works (link to a reference). If you need more help, just ask.


Oh, I didn't understanding back then, but kinda understand now. I will give it a try. Thanks, ParkourPenguin. Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites