Author Topic: Strange behavior of DOS assemblers  (Read 148 times)

Gunther

  • Member
  • *****
  • Posts: 3802
  • Forgive your enemies, but never forget their names
Strange behavior of DOS assemblers
« on: November 22, 2021, 12:14:47 PM »
Attached to this post is the archive video.zip. The folder video has two subdirectories: video1 and video2. In both is the source code and the running EXE of a simple Real Mode DOS program. In addition I have written a
batch file to generate the EXE with JWASM for DOS.

That's the background: At the moment I have to program for a company in an embedded DOS with an 80386 without FPU. Everything must run in 32 bit Protected Mode. I use therefore BIOS interrupts if possible. These
can be used in Real Mode as well as in Protected Mode. Why? A good DOS extender - like HX from Japheth - simply reflects the BIOS interrupts.

The logic of the program is very simple: It waits for a keystroke by calling the procedure Wait and then goes back to the operating system. The BIOS interrupt 16h is used for Wait.

Video1.exe does exactly that. But video2.exe doesn't call Wait, but immediately falls back to the command line. The difference between both programs is only in the order of the first two lines.

video1.asm:
Code: [Select]
    .model small
    .386

video2.asm:
Code: [Select]
    .386
    .model small

All other lines of the source code are identical.

That's a strange thing to say. I'm clearly emphasizing here that this obviously has nothing to do with JWASM. The TASM 4 behaves in the same way. How it looks with MASM, I can not say, because I do not have ML 6.11.
Maybe someone can test this?

I have tested the programs under DOSBox 0.74-3, FreeDos 1.1 with VirtualBox and native DOS 7. The results are always the same.

But what is the cause of this behavior? The processor directive is only about code generation. It can be placed anywhere in the source code. Or am I seeing this wrong?
« Last Edit: November 23, 2021, 08:58:52 PM by Gunther »
Get your facts first, and then you can distort them.

HSE

  • Member
  • *****
  • Posts: 1822
  • AMD 7-32 / i3 10-64
Re: Strange behavior of DOS assemblers
« Reply #1 on: November 22, 2021, 12:46:01 PM »
I think all ML versions must work. But you have to use link16.exe. (Still I don't installed Dosbox here).
Mathematics in Assembly: SmplMath

nidud

  • Member
  • *****
  • Posts: 2311
    • https://github.com/nidud/asmc
Re: Strange behavior of DOS assemblers
« Reply #2 on: November 22, 2021, 12:49:12 PM »
The bitness of the program is defined by the first segment, and as the default CPU is 8086 this will be WORD.

Model small will create two segments, CODE and DATA, based on the current CPU.

.model small
_TEXT segment WORD  PUBLIC 'CODE'
_TEXT ends
_DATA segment WORD  PUBLIC 'DATA'
_DATA ends

.386
.model small
_TEXT segment DWORD USE32 PUBLIC 'CODE'
_TEXT ends
_DATA segment DWORD USE32 PUBLIC 'DATA'
_DATA ends

Gunther

  • Member
  • *****
  • Posts: 3802
  • Forgive your enemies, but never forget their names
Re: Strange behavior of DOS assemblers
« Reply #3 on: November 22, 2021, 01:33:13 PM »
I think all ML versions must work. But you have to use link16.exe. (Still I don't installed Dosbox here).

Yes, they will work. But that's not the question. It is clear that you need a 16 bit linker. I bet that ML with link16 shows the same behavior.

The bitness of the program is defined by the first segment, and as the default CPU is 8086 this will be WORD.
This is probably the cause. This thread is mainly for informational purposes. I have been writing DOS programs for 40 years now, but the behavior has surprised me. We live and learn.
 
Get your facts first, and then you can distort them.

_japheth

  • Regular Member
  • *
  • Posts: 42
Re: Strange behavior of DOS assemblers
« Reply #4 on: November 22, 2021, 05:24:39 PM »
This is probably the cause. ...We live and learn.

Definitely. BTW, you can make masm(jwasm generate a listing file that includes the internally generated statements - use cmdline options -Fl AND -Sg.
The road to hell is paved with good intentions.

Gunther

  • Member
  • *****
  • Posts: 3802
  • Forgive your enemies, but never forget their names
Re: Strange behavior of DOS assemblers
« Reply #5 on: November 22, 2021, 06:41:11 PM »
Definitely. BTW, you can make masm(jwasm generate a listing file that includes the internally generated statements - use cmdline options -Fl AND -Sg.

Andreas, that's a good point.  :thumbsup:
Get your facts first, and then you can distort them.

Gunther

  • Member
  • *****
  • Posts: 3802
  • Forgive your enemies, but never forget their names
Re: Strange behavior of DOS assemblers
« Reply #6 on: November 23, 2021, 08:58:09 PM »
The processor directive can also be placed at the beginning of the source code. However, USE must then be used:
Code: [Select]
    .386
DGROUP group _DATA, STAK        ; automatic data group

_TEXT  segment word public use16 'CODE'
       assume  cs:_TEXT, ds:DGROUP, ss:STAK

_TEXT  ends

I've put a working example with the functionality of video1 as another attachment under post #1 of this thread.
Get your facts first, and then you can distort them.