flat assembler
Message board for the users of flat assembler.

Index > Main > call far 10000h

Author
Thread Post new topic Reply to topic
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1
Hi,

with 16 bit code in the first 64K of memory of a PC I want

to call a subroutine at 10000h

The following code doesnt seem to work:

Code:
use16
           .....
           mov ebx, .xyz
           mov edi, 0
           mov ds, di
           call far [ ds : bx ]

            ....

.xyz      dw   0, 01000h

    


Have I done that incorrectly? Razz


I found I can call the code with:

Code:
          use16
          call far 01000h : 0
    


this does work, but I am not sure what the correct way to return from the code is

any ideas?

is it retf? Mad

2 questions here,

1. what is the correct usage for the indirect

far call to 10000h from the first 64K of memory? Surprised

2. and what is the correct way to return from a DIRECT far call

to 10000h ? Shocked

furthermore for 1. can someone verify that fasm compiles this
correctly, as an IDA disassemble is a bit mystifying, it says

Code:
call dword ptr [ bx ] ; non fasm syntax Evil or Very Mad
    


ie 3 questions Confused
Post 28 Jan 2011, 21:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17247
Location: In your JS exploiting you and your system
revolution
Code:
.xyz      dw   0100h, 0 ;0x1000*16+0=0x10000

call dword ptr bx
call dword [bx]
;...
retf ;far return    
Post 28 Jan 2011, 22:07
View user's profile Send private message Visit poster's website Reply with quote
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1
revolution wrote:
Code:
.xyz      dw   0100h, 0 ;0x1000*16+0=0x10000

call dword ptr bx
call dword [bx]
;...
retf ;far return    



that doesnt work!

I tried it, and its wrong in 2 ways,

first it should be offset, segment as x86 is little endian

and NOT segment, offset. But for direct mode you

give the segment first.

secondly the segment should be 01000h and not 0100h,

but everything else I've tried also doesnt work.

so far only the following works:

Code:
call far 01000h : 0 
    


note here the segment IS given first as its not a

memory definition.

I know whether a usage works because at 10000h

I write an ascii character to the b8000h screen


if the character appears it works,
Post 29 Jan 2011, 02:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17247
Location: In your JS exploiting you and your system
revolution
lazer1 wrote:
first it should be offset, segment as x86 is little endian

and NOT segment, offset. But for direct mode you

give the segment first.

secondly the segment should be 01000h and not 0100h,
Good, so you do know how it works.
lazer1 wrote:
but everything else I've tried also doesnt work.

so far only the following works:

Code:
call far 01000h : 0 
    


What value do you load into bx? My guess is that you have this bx <= 0x0200 but in memory you use ds=0:bx points to some other place that is not .xyz. And probably 0x00007c00 <= .xyz <= 0x00007dff
Post 29 Jan 2011, 02:56
View user's profile Send private message Visit poster's website Reply with quote
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1
revolution wrote:

lazer1 wrote:
first it should be offset, segment as x86 is little endian

and NOT segment, offset. But for direct mode you

give the segment first.

secondly the segment should be 01000h and not 0100h,


Good, so you do know how it works.


unfortunately I DIDNT know how it works!

but I ran your suggestion "call dword ptr bx"

and it didnt work.

BUT for a call to the same segment which does work

I put the offset first in memory, thats how I know

the offset is first.

Code:
      ; this code is in memory BEFORE 10000h
      mov bx, .abc
      call far [ds:bx]
      ....
.abc    dw   8000h, 0 ; offset, segment

    


this code SUCCESSFULLY goes to 8000h

the call and the target address are both in the same segment

ds with 0


But I now have the code functioning using

your suggestion but with

offset, segment

Quote:



lazer1 wrote:
but everything else I've tried also doesnt work.

so far only the following works:

Code:
call far 01000h : 0 
    


What value do you load into bx? My guess is that you have this bx <= 0x0200 but in memory you use ds=0:bx points to some other place that is not .xyz. And probably 0x00007c00 <= .xyz <= 0x00007dff



I have the code functioning now using the instruction you gave,

but with offset, segment

Code:
use16
       ; this code is between 8000h and 0ffffh of memory

       mov ebx, .xyz
       mov edi, ebx
       and edi, 0ffff0000h
       shr edi, 4  ; should be 0
       mov ds, di   ; establish 0 as the segment,

       and ebx, 00000ffffh  ; should be a no-op, establishes the offset
 .me:   call dword ptr bx 

       ....

.xyz    dw   0, 1000h  ; offset, segment,   segment * 16 + offset

    


this now does function! Very Happy

note that the call and the target are different segments Embarassed

but I see now that for a different choice of segment they are

then the same segment Cool eg
Code:
       mov edi, .me ; see above fragment for .me
       shr edi, 4
       mov ds, di
    


but IMHO such nonstandard segments will be bug prone Mad

here a near call could be done,

I know whether the code functions because the code at 10000h

immediately renders a character to the 80x25 text screen

if that character appears then the target address is successfully

reached,


the above fragment has a lot of redundancy, but its best to

do it methodically as segment:offset is very bug prone,
Post 29 Jan 2011, 17:42
View user's profile Send private message Reply with quote
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1
I now use the earlier idea of
Code:
      use16
      call far 01000h : 0
    


because that works AND it uses no registers AND

I have verified by trying it that the return instruction is the

same as for the other idea. Very Happy
Post 06 Feb 2011, 21:50
View user's profile Send private message 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.

Powered by rwasa.