Page 1 of 1

Asm call to mono-address

Posted: Fri May 15, 2020 8:39 pm
by miraikolus
Now, I believe the following (simplified) should work, but is there anything better? celua and web didn't show anything but who knows .. some combination ..

Code: Select all

label(jitAddress)
registersymbol(jitAddress)
Jump:To:Address: //thanks to mono features
jitAddress:

newmem:
mov r11,[jitAddress]
call r11
Btw, can any1 explain me the purpose of the following (debugging only?):

Code: Select all

lea rax,[rax+rcx*8+20]
mov rax, [rax]

Re: Asm call to mono-address

Posted: Fri May 15, 2020 10:49 pm
by TimFun13
Googled "ce mono lua", which lead to [Link], and there listed is [Link]. So not really sure what you're trying to do it that wasn't it.

As for the ASM, it's using [Link] (load effective address) to set RAX to the address, then moving the value at that address to RAX.
mov rax,[rax+rcx*8+20] is the same thing and would be faster.

Re: Asm call to mono-address

Posted: Fri May 15, 2020 11:18 pm
by miraikolus
What I do want to do is easy, call a function I do know does what i want (on above code - of course i'd do checks & co, set parameters before, thus "simplified"). Now in LUA, there are few methods to resolve, at last i'll prob need [Link] while addr. needs to be conv. to int.
But I am act. looking for a more simple instruction in code, i mean both options do get executed before actual asm, but above will require less.

Yeah, I do know what lea does. I just don't get why unity does that ... is there some debug=0 val/cons not set or ....? (yeah this question is something different and requires some ... history with unity compil. & asm.

Re: Asm call to mono-address

Posted: Sat May 16, 2020 12:12 am
by TimFun13
miraikolus wrote:
Fri May 15, 2020 11:18 pm
What I do want to do is easy, call a function I do know does what i want (on above code - of course i'd do checks & co, set parameters before, thus "simplified"). Now in LUA, there are few methods to resolve, at last i'll prob need [Link] while addr. needs to be conv. to int.
But I am act. looking for a more simple instruction in code, i mean both options do get executed before actual asm, but above will require less.
...
I don't know if it's a language barrier or what. But that was painful to try and read, and after three tries I still don't understand what you're trying to say here.

As far as getting the address of a symbol just use [Link] or [Link].
miraikolus wrote:
Fri May 15, 2020 11:18 pm
...

Yeah, I do know what lea does. I just don't get why unity does that ...
Probably just something the compiler does.
miraikolus wrote:
Fri May 15, 2020 11:18 pm
... is there some debug=0 val/cons not set or ....? (yeah this question is something different and requires some ... history with unity compil. & asm.
Maybe but I have no idea, not really knowledgeable with the Unity Engine. But it might be defined and used in a way that the code that uses it is only compiled in a development version, thus it wouldn't even be in the release version; which would make for better optimization of the game at release. But again, not really sure.

Re: Asm call to mono-address

Posted: Sat May 16, 2020 1:21 am
by panraven
You can enclose the symbolic address with double quote to force interpret the content as address,
it should work in general not just mono.
call "Jump:To:Address"
--
the memory addressing like [rax+rcx*8+20] may be a form to access an item in an array type.
For instance, it is the item with size 8 (so *8) base zero index rcx whose 1st element is in address rax+20.
For mono, usually the array length may be locate -8 offset from its 1st element, eg. rax+18 .
But it should be read in context with up and down codes.

Lea may also to do simple constant multiply on registers, usually several Lea run together.

Re: Asm call to mono-address

Posted: Sat May 16, 2020 11:35 pm
by miraikolus
But it might be defined and used in a way that the code that uses it is only compiled in a development version, thus it wouldn't even be in the release version; which would make for better optimization of the game at release. But again, not really sure.
That's what i mean, it is a released game. So I do wonder why. May they just forgot to disable those dev flags. But any way, that was just my curiosity.
panraven wrote:
Sat May 16, 2020 1:21 am
call "Jump:To:Address"
.... right clear. I never had to use that for unity up to now. But it's clear that this is an option. Thanks, that's what I did need.

As for the other options - thanks for the note. But I do know generally and in that game exactly what each of the registers stand for and instructions do. It was just as written to ShyTwig16, that I don't know why the extra effort. Yeah, sometimes you want to get the addr ... mostly to store in some other memory addr . But storing in a register, next you do store the pointed addr into same register is .....
Any way, those explanations might do help others.