Page 1 of 1
Why the register call instruction is called "indirect"?
Posted: Thu Dec 25, 2014 7:37 am
by embryo
In case of following code we have some misleading name (as I see it).
Code: Select all
call EAX; push and jump to address in EAX
It is the case for indirection when the code is as such:
Code: Select all
call [EAX+0xf0]; push and jump to address that EAX and displacement point to.
But where is the indirection in the first case?
Re: Why the register call instruction is called "indirect"?
Posted: Thu Dec 25, 2014 8:02 am
by Octocontrabass
Direct: the destination address is part of the instruction.
Indirect: the destination address is not part of the instruction.
Seems pretty straightforward to me.
Re: Why the register call instruction is called "indirect"?
Posted: Thu Dec 25, 2014 8:40 am
by Antti
First of all, your comments are a little bit ambiguous. But yes, I think "call eax" is not very clear. Practically, it is more direct than indirect.
Code: Select all
org 0
bits 32
Start:
mov eax, SomeTable
call dword [eax+8] ; call "SomeProcedure" indirectly
mov eax, SomeProcedure
call eax ; call "SomeProcudure" directly/indirectly
call SomeProcedure ; call "SomeProcedure"
align 32
SomeTable:
dd 0x00000000 ; Entry 0
dd 0x00000000 ; Entry 1
dd SomeProcedure ; Entry 2
dd 0x00000000 ; Entry 3
dd 0x00000000 ; Entry 4
dd 0x00000000 ; Entry 5
dd 0x00000000 ; Entry 6
dd 0x00000000 ; Entry 7
SomeProcedure:
ret ;near return works for all calls above
Code: Select all
Address Instructions Assembly Comments
00000000 B8 20 00 00 00 mov eax, 0x00000020 absolute address of SomeTable
00000005 FF 50 08 call dword [eax+0x08] call absolute address stored at Entry 2
00000008 B8 40 00 00 00 mov eax, 0x00000040 absolute address of SomeProcedure
0000000D FF D0 call eax call absolute address stored in eax
0000000F E8 2C 00 00 00 call +0x0000002C relative displacement 0x0000002C
SomeTable
00000020 00 00 00 00 - Entry 0
00000024 00 00 00 00 - Entry 1
00000028 40 00 00 00 - Entry 2 (absolute address of SomeProcedure)
0000002C 00 00 00 00 - Entry 3
00000030 00 00 00 00 - Entry 4
00000034 00 00 00 00 - Entry 5
00000038 00 00 00 00 - Entry 6
0000003C 00 00 00 00 - Entry 7
00000040 C3 ret SomeProcedure instruction
Re: Why the register call instruction is called "indirect"?
Posted: Fri Dec 26, 2014 6:31 am
by embryo
Octocontrabass wrote:Direct: the destination address is part of the instruction.
Indirect: the destination address is not part of the instruction.
Seems pretty straightforward to me.
But does it seem to you that the following code is an indirection of any kind?
There should be some rules, and rules should be respected. If in one case there is no indirection then the same should be true for another case. There is square bracket notation in machine languages for indirections of any kind, why such rule is refused to be respected? That's why I see it as misleading.
Re: Why the register call instruction is called "indirect"?
Posted: Fri Dec 26, 2014 6:33 am
by embryo
Antti wrote:Practically, it is more direct than indirect.
And for those who study assembly it is a source of mistakes.
Re: Why the register call instruction is called "indirect"?
Posted: Fri Dec 26, 2014 6:41 am
by iansjack
Oh, come on! You are not jumping to EAX but to the address stored in EAX - hence indirect. This is absolutely basic stuff and not worthy of discussion here.
Re: Why the register call instruction is called "indirect"?
Posted: Fri Dec 26, 2014 7:11 am
by Octocontrabass
Code: Select all
MOV EAX, 8 ;Move immediate
CALL 8 ;Direct call
MOV EAX, EBX ;Move register
CALL EBX ;Indirect call register
MOV EAX, [8] ;Move direct
CALL [8] ;Indirect call direct
MOV EAX, [EBX] ;Move register indirect
CALL [EBX] ;Indirect call register indirect
There is a difference between "indirect call" and "register indirect". It sounds like you might be confusing the two.