flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > How to make a Call direct address

Author
Thread Post new topic Reply to topic
myoffice91



Joined: 08 Jan 2021
Posts: 4
myoffice91
I wanted to try and put the call 5C03B0h instruction, but it doesn't work because of a compilation error.

I know not efficient code due to extra tact
Code:
ConstExeCallTest1 dd 5C03B0h

mov eax,dword[ConstExeCallTest1]
call eax
    

There is a better option
Code:
proc Main
mov eax,5C03B0h-4
mov ecx,GetHotKeyFunction.SetCallAddres1+1
sub eax,ecx
mov dword[GetHotKeyFunction.SetCallAddres1+1],eax
ret
endp


proc GetHotKeyFunction
.SetCallAddres1:
call GetHotKeyFunction
ret
endp

    

But unnecessary code and a lot of writing and increasing the file size is inconvenient.


In my opinion, the most convenient macro, but does not work correctly = (
Code:
CreateCalladress 5C03B0h

macro   CreateCalladress addres1
{
  db 0E8h 
  local ..ot
..ot:
        dd addres1- (($-$)-..ot);
}


    

Help me parse the macro to make the call address work correctly?



Question?
1) Why call 5C03B0h is not implemented, but you can write mov eax, 5C03B0h.

2) What is the faster cycle per instruction
Code:
call 5C03B0h    

or
Code:
push 5C03B0h
ret    


or
Code:
mov eax, 5C03B0h
call eax
    



I know that the clock cycle is longer call dword [ConstExeCallTest1]


Last edited by myoffice91 on 08 Jan 2021, 11:37; edited 1 time in total
Post 08 Jan 2021, 10:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18182
Location: In your JS exploiting you and your system
revolution
Code:
my_address dd 5C03B0h
call [my_address]    
Post 08 Jan 2021, 11:08
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18182
Location: In your JS exploiting you and your system
revolution
myoffice91 wrote:
Question?
1) Why call 5C03B0h is not implemented, but you can write mov eax, 5C03B0h.
The x86 architecture doesn't support instructions of that form.
myoffice91 wrote:
I know that the clock cycle is longer call dword [ConstExeCallTest1]
Clock cycle counts depend upon many things, including, but not limited to, the exact CPU you have, the memory timing, the contents of the cache, the type and state of instructions both before and after your call, etc., etc., etc.

If this single instruction is going to cause a bottleneck then I would be very surprised.
Post 08 Jan 2021, 11:12
View user's profile Send private message Visit poster's website Reply with quote
myoffice91



Joined: 08 Jan 2021
Posts: 4
myoffice91
revolution wrote:
Code:
my_address dd 5C03B0h
call [my_address]    

I use this method, but I'm tired of creating a lot of constant variables.
I only need one line of code like this CreateCalladress 5C03B0h


It may be better to modify FASM.exe to support call 5C03B0h
I don't know where the exact source code is for "call" for the support address, not the names.
Post 08 Jan 2021, 11:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18182
Location: In your JS exploiting you and your system
revolution
If you modify fasm it won't help. It is the CPU that doesn't have the instruction.
Code:
macro CreateCalladress address {
        local ..addr, ..call
        jmp ..call
        ..addr dd address
        ..call: call [..addr]
}
CreateCalladress 5C03B0h    
Post 08 Jan 2021, 11:19
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1080
Roman
Quote:

macro CreateCalladress address {
local ..addr, ..call
jmp ..call
..addr dd address
..call: call [..addr]
}

Wau !
My solution
Code:
macro CreateCalladress address {
        local ..return
        push  ..return
        jmp   dword [address]
..return:        
}

macro CreateCalladress address,Name {
        local ..return
        push  ..return
        jmp   dword [address]
..return:        
        Name equ ..return-4
}
    


Last edited by Roman on 08 Jan 2021, 12:11; edited 2 times in total
Post 08 Jan 2021, 11:43
View user's profile Send private message Reply with quote
myoffice91



Joined: 08 Jan 2021
Posts: 4
myoffice91
revolution wrote:
myoffice91 wrote:
Question?
1) Why call 5C03B0h is not implemented, but you can write mov eax, 5C03B0h.
The x86 architecture doesn't support instructions of that form.


What does x86 not support the call instruction? see screenshot

Image
mov eax, dword ptr ds:[0x719DB05A] ; output 8EBE5352
Using calculator -> Programmer -> 4 bytes -> HEX
5C03B0h-719DB059h-5=8EBE5352h




FASM - my macro incorrectly handling call address
Image




revolution wrote:

myoffice91 wrote:
I know that the clock cycle is longer call dword [ConstExeCallTest1]
Clock cycle counts depend upon many things, including, but not limited to, the exact CPU you have, the memory timing, the contents of the cache, the type and state of instructions both before and after your call, etc., etc., etc.

If this single instruction is going to cause a bottleneck then I would be very surprised.

I will say that the worst instruction is add dword [edi], 12. One person complains that the game is slow or the sounds stutter, but he is a modern i7 processor and a different computer. is also the same. And I have no problem, the processor QUAD cache is 12MB. Clearly the cache memory is clogged due to the add dword [] instruction. =).


revolution wrote:
Code:
macro CreateCalladress address {
        local ..addr, ..call
        jmp ..call
        ..addr dd address
        ..call: call [..addr]
}
CreateCalladress 5C03B0h    


An interesting macro, a coolly difficult disassembler. Not only are two extra instructions, but it is difficult how much length the distance to spoof the address.
Image



_____
updated the first post, because of the confused macro.




Roman wrote:
Quote:

macro CreateCalladress address {
local ..addr, ..call
jmp ..call
..addr dd address
..call: call [..addr]
}

Wau !
My solution
Code:
macro CreateCalladress address {
        local ..return
        push  ..return
        jmp   dword [address]
..return:        
}
    

Feedback: wow handy code! The code has become cleaner Smile.



I'm waiting for the solution revolutionary macro in one instruction call from address Cool



What is it needed for? in the game the events of the nanosecond does the function, but I didn't want to slow down the game and increase the CPU.

[spoiler]
I am developing Wizardry 8 Fan Patch 1.28 written under FASM
[/spoiler]
Post 08 Jan 2021, 12:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18182
Location: In your JS exploiting you and your system
revolution
If your PE file (I assume you are using a PE format) has relocations then you can't encode a fixed address in a call. It is all relative.

Also note that Roman's code isn't truly what you want. It doesn't call the address, it calls the dword value at the address.
Post 08 Jan 2021, 12:11
View user's profile Send private message Visit poster's website Reply with quote
myoffice91



Joined: 08 Jan 2021
Posts: 4
myoffice91
revolution wrote:
If your PE file (I assume you are using a PE format) has relocations then you can't encode a fixed address in a call. It is all relative.

my code:
Code:
format PE GUI 4.0 DLL at 0    


Saw the forum, developer Tomasz Grysztar
https://board.flatassembler.net/topic.php?t=37
But it doesn't work.

_____
I'm waiting, the great developer Tomasz Grysztar is able to solve problems: D
Post 08 Jan 2021, 12:18
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 954
Location: Belarus
DimonSoft
myoffice91 wrote:
Code:
format PE GUI 4.0 DLL at 0    

I hope you’re not really going to put it exactly there.
Post 09 Jan 2021, 21:10
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3290
Location: vpcmipstrm
bitRAKE
Without relocation information, a zero base address will always fail - due to relocation being required.

_________________
¯\(°_o)/¯ unlicense.org
Post 10 Jan 2021, 08:59
View user's profile Send private message Visit poster's website 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.