VOGONS


First post, by paprika

User metadata
Rank Newbie
Rank
Newbie

Probably a long shot but maybe someone here knows.

I'm trying to cross-compile assembly code from a modern machine, using http://sun.hasenbraten.de/vasm/ compiler and http://sun.hasenbraten.de/vlink/ linker, to 8088 XT.

I am able to compile basic code (to display a string) on MS-DOS using MASM, but I'm unable to replicate that with vasm. I'm not sure the problem is in my syntax, or in how I call vasm.

This code (written, compiled, and linked in MASM) executes and correctly displays a string:

ASSUME     CS :CODE, DS :DATA                                                                                                                            
DATA SEGMENT
MESSAGE DB 0DH, 0AH, " HELLO BELLO", 0DH, 0AH, "$"

DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AH, 09H
MOV DX, OFFSET MESSAGE
INT 21H
MOV AH, 4CH
INT 21H
CODE ENDS
END START

Whereas this code also compiles and executes, but displays garbage when run under DOS:

.code16

.org 0x100

start:
mov $0x9, %ah
lea msg, %dx
int $21
mov $0x4c, %ax
int $21

msg:
.byte "hello bello", 0x0a

This is how I run the compiler:

vasmx86_std -m8086 -Faout mmm.asm -o mmm.obj

and this is how I run the linker:

vlink mmm.obj -o mmm.exe

Any ideas?

--
Forgotten Computer
Computers and stuff at my YouTube Channel

Reply 1 of 9, by vstrakh

User metadata
Rank Member
Rank
Member

The ".org 100h" suggests you're compiling for .COM file, but you're linking it as .EXE.
The offset to the message was likely taken relative to the different segment, not the one you're thinking.

Reply 2 of 9, by paprika

User metadata
Rank Newbie
Rank
Newbie

Thank you. This would make sense as the "message" I'm getting displayed seems to be a random string of chars picked from a different segment of memory...

If that's the case, do you happen to know how to link for .com? vlink help doesn't seem to mention this.

--
Forgotten Computer
Computers and stuff at my YouTube Channel

Reply 3 of 9, by akula65

User metadata
Rank Oldbie
Rank
Oldbie

You may want to look into the EXE2BIN DOS utility to do the .EXE to .COM conversion. However, note that the utility puts restrictions on how the .EXE must be created (segments, entry point, etc.) in order for the conversion to be successful.

Reply 4 of 9, by Namrok

User metadata
Rank Oldbie
Rank
Oldbie

Funny, I just started doing this as well. I have a NuXT in the mail, and I have a compulsive need to be able to develop for every device I own... even if I never actually do.

My toolchain is Visual Studio Code with tasks set up to use NASM to build obj files, and then ALINK to link them into an EXE. Then it launches into DOSBOX.

Still working out how to export breakpoints I've set in Visual Studio Code into DOSBOX. Found a VSC extension which dumps your breakpoints as JSON. NASM will generate a dbg file with the addresses of labels relative to their segment. ALINK can dump the map of where the segments are. I think combining all these things, and a patched version of DOSBOX that takes a debug autoexec full of BP commands, it should work. About halfway through my first attempt at a script that will glue it all together.

Win95/DOS 7.1 - P233 MMX (@2.5 x 100 FSB), Diamond Viper V330 AGP, SB16 CT2800
Win98 - K6-2+ 500, GF2 MX, SB AWE 64 CT4500, SBLive CT4780
Win98 - Pentium III 1000, GF2 GTS, SBLive CT4760
WinXP - Athlon 64 3200+, GF 7800 GS, Audigy 2 ZS

Reply 5 of 9, by vstrakh

User metadata
Rank Member
Rank
Member

What kind of .EXE are you getting in the end?
I tried to use vasm/vlink, building it from sources. But I can't find DOS EXE support there.
The EXE I've got after linking is not a DOS executable at all, it's not EXE (no "MZ" signature) and not a COM - 32 bytes of something in front of actual code cannot exist in COM.

00000000 00 00 03 F3 │ 00 00 00 00 │ 00 00 00 01 │ 00 00 00 00 ................
00000010 00 00 00 00 │ 00 00 00 07 │ 00 00 03 E9 │ 00 00 00 07 ................
00000020 B4 09 8D 16 │ 0D 01 CD 15 │ B8 4C 00 CD │ 15 68 65 6C .........L...hel
00000030 6C 6F 20 62 │ 65 6C 6C 6F │ 0A 00 00 00 │ 00 00 03 F2 lo bello........

Reply 6 of 9, by paprika

User metadata
Rank Newbie
Rank
Newbie

Hi all, thank you for trying to help. I'm getting the same results after binary adjustment with exe2bin.

As for the format of the output, here are dumps:

mik:pc_speaker eu$ vasmx86_std -m8086 -Faout mmm.asm -o mmm.obj
vasm 1.8l (c) in 2002-2021 Volker Barthelmann
vasm x86 cpu backend 0.7a (c) 2005-2006,2011,2015-2019 Frank Wille
vasm std syntax module 5.3b (c) 2002-2021 Volker Barthelmann
vasm a.out output module 0.8 (c) 2008-2016,2020 Frank Wille

text(acrwx1): 27 bytes
mik:pc_speaker eu$ hexdump -C mmm.obj
00000000 40 64 01 07 1c 00 00 00 00 00 00 00 00 00 00 00 |@d..............|
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000020 68 65 6c 6c 6f 20 62 65 6c 6c 6f 0a 8a 26 09 00 |hello bello..&..|
00000030 8d 16 00 01 cd 15 a1 4c 00 cd 15 00 |....?.?L.?..|
0000003c
mik:pc_speaker eu$ vlink mmm.obj -o mmm.exe
mik:pc_speaker eu$ hexdump -C mmm.exe
00000000 00 00 03 f3 00 00 00 00 00 00 00 01 00 00 00 00 |...?............|
00000010 00 00 00 00 00 00 00 07 00 00 03 e9 00 00 00 07 |...........?....|
00000020 68 65 6c 6c 6f 20 62 65 6c 6c 6f 0a 8a 26 09 00 |hello bello..&..|
00000030 8d 16 00 01 cd 15 a1 4c 00 cd 15 00 00 00 03 f2 |....?.?L.?.....?|
00000040
mik:pc_speaker eu$

--
Forgotten Computer
Computers and stuff at my YouTube Channel

Reply 7 of 9, by paprika

User metadata
Rank Newbie
Rank
Newbie

Yeah, looking at this now it seems this is not the expected DOS exe or com format. I'm still feeling like I'm missing something obvious, as I find it hard to believe that I was able to assemble code with vasm for all kinds architectures including Amigas, Z80, several flavors of Apple, etc. but cannot assemble for early DOS...

Anyway, I have the last resort which is to learn Intel syntax and program natively in DOS using MASM. Not the end of the world 😀

--
Forgotten Computer
Computers and stuff at my YouTube Channel

Reply 8 of 9, by vstrakh

User metadata
Rank Member
Rank
Member

It looks that for .COM format it would be ok to specify the output format as "-b rawbin1", the .COM is practically the rom dump - no relocations, no segments.
You will be limited to TINY memory model - all segment registers are pointing to PSP, all offsets are relative to the same segment, and the size of your app is limited to <64K

So using "vlink mmm.obj -b rawbin1 -o mmm.com" should produce your executable.

There are number of issues with your vasm example too.
Either you're using decimal number when calling int 21h (it should be "int $0x21", comparing to the syntax of other loads), or maybe I don't get it why "int $21" gets compiled to "int 15h", the vasm pdf doc say the $ prefix is for hexadecimal numbers...
And your message didn't end with '$' sign, the DOS expects dollar sign to terminate the message.

Fixing this and using rawbin1 format gave me a pretty normal looking and runnable .com file.

Reply 9 of 9, by paprika

User metadata
Rank Newbie
Rank
Newbie

Yaaay! It worked 😀 Thank you vstrakh!

The bugs creeped in because I was experimenting with different notations — the vasm's "std" syntax is different from the MOT one I used for other projects and had a hard time switching.

All is starting to make sense now. Thank you again for helping!

--
Forgotten Computer
Computers and stuff at my YouTube Channel