Why the register call instruction is called "indirect"?

Programming, for all ages and all languages.
Post Reply
embryo

Why the register call instruction is called "indirect"?

Post 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?
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why the register call instruction is called "indirect"?

Post by Octocontrabass »

Direct: the destination address is part of the instruction.

Code: Select all

CALL thing
Indirect: the destination address is not part of the instruction.

Code: Select all

MOV  EAX, thing
CALL EAX
Seems pretty straightforward to me.
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Why the register call instruction is called "indirect"?

Post 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
embryo

Re: Why the register call instruction is called "indirect"?

Post by embryo »

Octocontrabass wrote:Direct: the destination address is part of the instruction.

Code: Select all

CALL thing
Indirect: the destination address is not part of the instruction.

Code: Select all

MOV  EAX, thing
CALL EAX
Seems pretty straightforward to me.
But does it seem to you that the following code is an indirection of any kind?

Code: Select all

MOV EAX, EBX
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.
embryo

Re: Why the register call instruction is called "indirect"?

Post by embryo »

Antti wrote:Practically, it is more direct than indirect.
And for those who study assembly it is a source of mistakes.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Why the register call instruction is called "indirect"?

Post 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.
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why the register call instruction is called "indirect"?

Post 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.
Post Reply