Author Topic: how to split my 16bit/dos/medium model sample into files  (Read 9969 times)

Offline llm

  • Jr. Member
  • *
  • Posts: 3
how to split my 16bit/dos/medium model sample into files
« on: September 17, 2019, 02:37:09 PM »
i tried serveral times - all my postings were rejected, now it works - no idea what i've changed
« Last Edit: September 17, 2019, 03:18:04 PM by llm »

Offline llm

  • Jr. Member
  • *
  • Posts: 3
how to split my 16bit/dos/medium model sample into files
« Reply #1 on: September 17, 2019, 03:16:43 PM »
i've got a 16bit/dos/medium model single.asm that builds to a working dos exe (checked with dosbox and IDA Pro)

using lastest available versions of
nasm.exe: 2.14.02
wlink: Open Watcom Linker Version 2.0 beta Sep 17 2019 01:44:30 (64-bit)
link.exe: Microsoft (R) Segmented Executable Linker Version 5.60.339 Dec 5 1994 (latest 16bit able version)
ulink.exe: UniLink v1.11 [beta] (build 11.27) from ftp://ftp.styx.cabel.net/pub/UniLink/
optlink.exe: OPTLINK (R) for Win32 Release 8.00.17 (from the dmd package: dmd.2.088.0.windows)

single.asm
Code: [Select]
BITS 16

segment seg000 ; align=16

text: db 'Hello World!',0ah,0dh,'$'

segment seg001 ; align=16

..start:
mov ax,seg000
mov ds,ax

call far print

mov ax,0x4c00
int 0x21

segment seg002 ; align=16

print:
mov dx,text
mov ah,9
int 0x21
retf

segment seg003 stack
resb 256

build
Code: [Select]
nasm.exe -f obj -o single.obj ..\nasm.single.asm
ulink.exe single.obj, single.exe, single.map

then i try to split the program up into a file per segment but that fails to link

seg000
Code: [Select]
BITS 16

segment seg000 public

global text

text: db 'Hello World!',0ah,0dh,'$'

seg001
Code: [Select]
BITS 16

extern seg000
extern print

segment seg001 public

..start:
mov ax,seg000
mov ds,ax

call far print

mov ax,0x4c00
int 0x21

seg002
Code: [Select]
BITS 16

segment seg002 public

extern text

global print

print:
mov dx,text
mov ah,9
int 0x21
retf

seg003
Code: [Select]
BITS 16

segment seg003 stack
resb 256

build
Code: [Select]
nasm.exe -f obj -o seg000.obj seg000.asm
nasm.exe -f obj -o seg001.obj seg001.asm
nasm.exe -f obj -o seg002.obj seg002.asm
nasm.exe -f obj -o seg003.obj seg003.asm
ulink.exe seg000.obj seg001.obj seg002.obj seg003.obj, multi.exe, multi.map

this gives me a linker error that the seg000 reference in seg001.obj can't be resolved

ulink.exe:
Code: [Select]
UniLink v1.11 [beta] (build 11.27)
Error: Unresolved external 'seg000' referenced from 'seg001.obj'

link.exe:
Code: [Select]
Microsoft (R) Segmented Executable Linker  Version 5.60.339 Dec  5 1994
Copyright (C) Microsoft Corp 1984-1993.  All rights reserved.
seg001.obj(seg001.asm) : error L2029: 'seg000' : unresolved external
There was 1 error detected

wlink.exe
Code: [Select]
Open Watcom Linker Version 2.0 beta Sep 17 2019 01:44:30 (64-bit)
Copyright (c) 2002-2019 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
loading object files
Error! E2028: seg000 is an undefined reference
creating map file
creating a DOS executable
file seg001.obj(seg001.asm): undefined symbol seg000

optlink.exe:
Code: [Select]
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
seg001.obj(seg001)
 Error 42: Symbol Undefined seg000


the single.asm works with all linkers

any ideas?

my goals: 100% identical single.exe and multi.exe (code and segment ordering)

but linking at all would be great :)

« Last Edit: September 17, 2019, 04:47:45 PM by llm »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: how to split my 16bit/dos/medium model sample into files
« Reply #2 on: September 17, 2019, 08:52:31 PM »
Hi lim,

Welcome to the forum. Congratulations on your determination!

At one time, I knew how to do this... but that was a long time ago!

My first thought is to declare "global seg000" alongside of "global text". Try that and see if it helps any...

I wish I could help more but I'm old and tired and my memory is all shot. Examples I had were lost in a crash with no backup... Good luck!

Best,
Frank


Offline llm

  • Jr. Member
  • *
  • Posts: 3
Re: how to split my 16bit/dos/medium model sample into files
« Reply #3 on: September 18, 2019, 03:56:03 AM »
Quote
My first thought is to declare "global seg000" alongside of "global text". Try that and see if it helps any...

global seg000 in seg000.asm does not help and i don't think that the segment is handled like an external at all

but i solved it by adding an segment "forward declaration" inc that contains all segments (empty and in order)

segments.inc
Code: [Select]
BITS 16

segment seg000
segment seg001
segment seg002
segment seg003 stack

and included that

seg001.asm
Code: [Select]
BITS 16

%include "segments.inc"

extern print

segment seg001

..start:
mov ax,seg000
mov ds,ax

call far print

mov ax,0x4c00
int 0x21

seems to work - but i still don't know if it is the "correct" way of doing it
« Last Edit: September 18, 2019, 03:59:29 AM by llm »