Help - indirect call 
Author Message
 Help - indirect call

I'm a novice to ASM programming, but have used C for 10 years.

I need to call a driver how's address I get using int 2fh and returned
in ES:SI..

I made the following code:

        ;entry point is in es:di
        ;save entry point on stack

        mov     ax,es
        mov     word ptr [bp-2],ax
        mov     ax,di
        mov     word ptr [bp-4],ax

        ; point es:si to C struct
        mov     si,word ptr [bp+4]
        mov     ax,ds
        mov     es,ax

        ;call    [bp-4]

        mov     bx,bp
        sub     bx,4

        call far [bx]

Using Turbo Debug I see that BP-4 seems to point to the correct
address, but the call instruction jumps to the wrong address. As you
can see I have tried both call [bp-4] and using bx as pointer.

What am I doing wrong?



Tue, 06 Oct 1998 03:00:00 GMT  
 Help - indirect call

I'm a novice to ASM programming, but have used C for 10 years.

I need to call a driver how's address I get using int 2fh and returned
in ES:SI..

I made the following code:

        ;entry point is in es:di
        ;save entry point on stack

        mov     ax,es
        mov     word ptr [bp-2],ax
        mov     ax,di
        mov     word ptr [bp-4],ax

        ; point es:si to C struct
        mov     si,word ptr [bp+4]
        mov     ax,ds
        mov     es,ax

        ;call    [bp-4]

        mov     bx,bp
        sub     bx,4

        call far [bx]

Using Turbo Debug I see that BP-4 seems to point to the correct
address, but the call instruction jumps to the wrong address. As you
can see I have tried both call [bp-4] and using bx as pointer.

What am I doing wrong?



Tue, 06 Oct 1998 03:00:00 GMT  
 Help - indirect call

Quote:

>        call far [bx]
>Using Turbo Debug I see that BP-4 seems to point to the correct
>address, but the call instruction jumps to the wrong address. As you
>can see I have tried both call [bp-4] and using bx as pointer.

I found the problem but not the cause.

When I disassembled the code it said "call far [bx-2]", not "call far
[bx]" as the program states. I put in "db 0ffh, 01fh"  instead of the
call and it works like it should.

I'm using TASM. Is this a known bug in TASM?



Thu, 08 Oct 1998 03:00:00 GMT  
 Help - indirect call

Quote:

>        call far [bx]

...
>I found the problem but not the cause.

>When I disassembled the code it said "call far [bx-2]", not "call far
>[bx]" as the program states.

The cause of the problem is this:
'far' is a predefined constant equaling -2
'near' = -1
'byte' = 1
'word' = 2
etc.

So 'call far ptr label' can also be written as 'call -2 ptr label'

The operator [] works as + so you have 'call -2 + [bx]'

You should write:

call dword ptr [bx]

Of course you can also write:  'call 4 ptr [bx]'   :)

Agner Fog



Fri, 09 Oct 1998 03:00:00 GMT  
 Help - indirect call

Quote:

>I'm a novice to ASM programming, but have used C for 10 years.

>I need to call a driver how's address I get using int 2fh and returned
>in ES:SI..

>I made the following code:

>        ;entry point is in es:di
>        ;save entry point on stack

>        mov     ax,es
>        mov     word ptr [bp-2],ax
>        mov     ax,di
>        mov     word ptr [bp-4],ax

>        ; point es:si to C struct
>        mov     si,word ptr [bp+4]
>        mov     ax,ds
>        mov     es,ax

>        ;call    [bp-4]

>        mov     bx,bp
>        sub     bx,4

>        call far [bx]

>Using Turbo Debug I see that BP-4 seems to point to the correct
>address, but the call instruction jumps to the wrong address. As you
>can see I have tried both call [bp-4] and using bx as pointer.

>What am I doing wrong?

I'm not so good in assembly myself, but did you try call dword ptr [bx]?
Excerpt from a book: 'The words NEAR and FAR are always used with
reference to code labels, while WORD and DWORD are used with memory
references.'

--
Martin Goebbel


 / ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \  
|   / ~ \                                           / ~ \   |
|\  \    |     All that we see or seem             |    /  /|
|  \    /|     Is but a dream within a dream       |\    /  |
|    ~~  |                    E. A. Poe            |  ~~    |
|        |      Writing programs in C has          |        |
|        |      never led to any good.             |        |                  
|        |                    The Dark Avenger     |        |
|        |                                         |        |
 \       |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|       /
   \    /                                           \    /
     ~~                                               ~~



Wed, 14 Oct 1998 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Q: Interfacing C/ADA: Indirect Calls

2. Indirect calls using MASM 6.1 (how?)

3. indirect call with MASM?

4. indirect function calls and variable variables

5. Indirect function member calls

6. Indirect calls

7. Indirect calls

8. indirect function calls and variable variables

9. Question regarding indirect function calls

10. indirect **keyword calls

11. please help,indirect addressing problems in 68000

12. Urgent Help: Indirect Referencing problem

 

 
Powered by phpBB® Forum Software