Author Topic: Writing FAR procedures in different sections  (Read 7402 times)

Offline S Mahen

  • Jr. Member
  • *
  • Posts: 21
Writing FAR procedures in different sections
« on: January 21, 2014, 07:29:22 AM »
Hi, I am trying to implement a code for the statement in which I am suppose write 8086 code in two different segments(Module_A & Module_B), far procedures defined in Module_B are to be called from Module_A and values defined in section .data of Module_A are used in Module_B to perform different operations.

I tried this with MASM/TASM, Windows XP and it is working there.

Now I'm using Fedora 20 with nasm 2.10.7.

Please guide me how to go ahead?

Thanks in advance.

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: Writing FAR procedures in different sections
« Reply #1 on: January 21, 2014, 08:02:40 AM »
Hi!

I'm not an expert, but i would try something like this:

segment A
             procedure
segment B
             procedure

I think, at first, you have to select/switch/change a code segment, then call your procedure.

Select segment A -> Call procedure
Select segment B -> Call procedure

EDIT:
Here is more info: Complete 8086 instruction set - Gabriele Cecchetti
See instruction CALL, ~ On page 6, there is a far call example.



« Last Edit: January 21, 2014, 10:55:43 AM by encryptor256 »
Encryptor256's Investigation \ Research Department.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Writing FAR procedures in different sections
« Reply #2 on: January 21, 2014, 11:06:01 AM »
You can use code and data in different modules - just declare symbols "global" if they're defined in this module and need to be used in another - and declare 'em "extern" if they're used in this module but defined in another. Then put both (all) .o files on the command line to ld (or gcc).

"FAR", however, is more of a real mode, segmented memory model thing, as it involves changing the segment registers to some other 64k segment. In Windows/Linux/BSD/OSX (probably others) we've got a "flat" memory model, in which each segment spans the whole 4G (or more on a 64-bit system). There would be no point to a "far" procedure.

Nasm will let you declare arbitrary section names and attributes. I'd have to experiment to see what it would do if you tried "segment .text" and "segment .text2 exec" and a far call between 'em... and you can do that... I doubt if it would work.

Best,
Frank

Edit: You might find this information on segment registers interesting:
http://mirror.freedoors.org/Geezer-1/johnfine/segments.htm
« Last Edit: January 21, 2014, 11:31:16 AM by Frank Kotler »

Offline avcaballero

  • Full Member
  • **
  • Posts: 132
  • Country: es
    • Abre los Ojos al Ensamblador
Re: Writing FAR procedures in different sections
« Reply #3 on: January 22, 2014, 08:34:58 AM »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Writing FAR procedures in different sections
« Reply #4 on: January 22, 2014, 12:08:14 PM »
Maybe I'm confused about what we're trying to do. Here's what the old Nasm Manual instruction set reference says about "call":

http://home.myfairpoint.net/fbkotler/nasmdocc.html#section-A.4.18

For clarity:
Quote
I tried this with MASM/TASM, Windows XP and it is working there.
This was with real mode (16-bit) code, right? Not for Windows?
Quote
Now I'm using Fedora 20 with nasm 2.10.7.
And now you want to do it in Linux? Or is this for DosBox?

Best,
Frank