OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 25, 2024 4:24 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Why the register call instruction is called "indirect"?
PostPosted: Thu Dec 25, 2014 7:37 am 
In case of following code we have some misleading name (as I see it).
Code:
call EAX; push and jump to address in EAX

It is the case for indirection when the code is as such:
Code:
call [EAX+0xf0]; push and jump to address that EAX and displacement point to.

But where is the indirection in the first case?


Top
  
 
 Post subject: Re: Why the register call instruction is called "indirect"?
PostPosted: Thu Dec 25, 2014 8:02 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5145
Direct: the destination address is part of the instruction.
Code:
CALL thing


Indirect: the destination address is not part of the instruction.
Code:
MOV  EAX, thing
CALL EAX


Seems pretty straightforward to me.


Top
 Profile  
 
 Post subject: Re: Why the register call instruction is called "indirect"?
PostPosted: Thu Dec 25, 2014 8:40 am 
Offline
Member
Member

Joined: Thu Jul 05, 2012 5:12 am
Posts: 923
Location: Finland
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:
        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:
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

_________________
Undefined behavior since 2012


Top
 Profile  
 
 Post subject: Re: Why the register call instruction is called "indirect"?
PostPosted: Fri Dec 26, 2014 6:31 am 
Octocontrabass wrote:
Direct: the destination address is part of the instruction.
Code:
CALL thing


Indirect: the destination address is not part of the instruction.
Code:
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:
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.


Top
  
 
 Post subject: Re: Why the register call instruction is called "indirect"?
PostPosted: Fri Dec 26, 2014 6:33 am 
Antti wrote:
Practically, it is more direct than indirect.

And for those who study assembly it is a source of mistakes.


Top
  
 
 Post subject: Re: Why the register call instruction is called "indirect"?
PostPosted: Fri Dec 26, 2014 6:41 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: Why the register call instruction is called "indirect"?
PostPosted: Fri Dec 26, 2014 7:11 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5145
Code:
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 132 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group