News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How to assemble code with JWASM so that it starts at 100h when org 100h is set?

Started by bugthis, May 01, 2023, 04:01:43 AM

Previous topic - Next topic

bugthis

As far as i know from address XXXX:0000 until XXXX:0100 is DOS's Program Segment Prefix (PSP) and DEBUG.EXE itself prefers to start code at adress 100h if it is started without an EXE as parameter, thus i tried to archive the same in my assembly source code.

That's why i inserted a org 100h directive in my source code

.MODEL SMALL, C
.STACK 256
.DOSSEG

.DATA

.CODE
   org 100h
START:
   ...
END START


But when i open the compiled EXE with debug, debug starts at address 100h like intended (IP points to 100h), but the actual code is still starting at address XXXX:0000h.
Thus IP = 100 h just points at the middle of my program.
What i am doing wrong?

The JWASMR parameter i used was:
jwasmr -mz program.asm

Gunther

Bugthis,

Quote from: bugthis on May 01, 2023, 04:01:43 AM
jwasmr -mz program.asm
the switch -mz produces an *.exe file. If you want to produce a *.com file try this:

;--- this is a very simple 16bit "hello world" for DOS.
;--- assemble: JWasm -bin -Fo Dos1.com Dos1.asm

    .model tiny

    .data

str1    db 13,10,"Hello, world!",13,10,'$'

    .code

    org 100h

start:
    mov ah, 09h
    mov dx, offset str1
    int 21h
    mov ax, 4c00h
    int 21h

    end start

It is part of the examples of JWASM.
You have to know the facts before you can distort them.

mineiro

You can find an "int 20h" (0CDh 20h) in PSP space that means end this program and return control do command.com (command interpreter).
Generally .com programs ends with int 20h.
Assemble with -bin switch, rename .bin to .com.
Try a program with only ret instruction, and "int 20h" in PSP will enter in scene.

Remember to search the old archived board:  :thumbsup:
https://www.masmforum.com/board/
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

bugthis

Quote from: Gunther on May 01, 2023, 04:56:37 AM
Bugthis,

Quote from: bugthis on May 01, 2023, 04:01:43 AM
jwasmr -mz program.asm
the switch -mz produces an *.exe file. If you want to produce a *.com file try this:

;--- this is a very simple 16bit "hello world" for DOS.
;--- assemble: JWasm -bin -Fo Dos1.com Dos1.asm

    .model tiny

    .data

str1    db 13,10,"Hello, world!",13,10,'$'

    .code

    org 100h

start:
    mov ah, 09h
    mov dx, offset str1
    int 21h
    mov ax, 4c00h
    int 21h

    end start

It is part of the examples of JWASM.

Thanks.
I thought PSP is also available for EXE files. I didn't knew I had to create a COM file for the code to start at 100h.

But why does

JWasm -bin -Fo program.com program.asm

fail with the error message

PROGRAM.ASM : Error A2198: Invalid fixup type for BIN: 8 at location _TEXT.101


When i comment this line of code with a semicolon:

MOV AX, @DATA

Then it compiles.


bugthis

Quote from: mineiro on May 01, 2023, 08:26:19 AM
You can find an "int 20h" (0CDh 20h) in PSP space that means end this program and return control do command.com (command interpreter).
Generally .com programs ends with int 20h.
Assemble with -bin switch, rename .bin to .com.
Try a program with only ret instruction, and "int 20h" in PSP will enter in scene.
Thank you for your information. I didn't knew that.

But why isn't this

  MOV AX, 0CDh
  INT 20h

routine not used for all programs?

Why are some ended with

  MOV AX, 4C00h ; with return code, in this case 00h in AL
  INT 21h

or

  MOV AX, 0000h ; without return code.
  INT 21h

?

FORTRANS

Hi,

Quote from: bugthis on May 01, 2023, 10:26:12 PM

I thought PSP is also available for EXE files. I didn't knew I had to create a COM file for the code to start at 100h.

   The PSP is used by MS_DOS for both *.COM and *.EXE programs.  In a
COM program the CS register points to the start of the PSP.  In an EXE
program the CS register points to where you told MS-DOS the entry point
of your program is.  The "ORG 100H" is used to set the IP register to the
normal entry point in a COM program, skipping over the PSP.  In an EXE
The IP can be set to 0000H, as that will start execution as CS:IP points to
the entry point of your code (at least if you set things up normally).

Regards,

Steve N.

FORTRANS

Hi,

Quote from: bugthis on May 01, 2023, 10:33:03 PM
But why isn't this

  MOV AX, 0CDh
  INT 20h

routine not used for all programs?

   MS-DOS 1.0 used "INT 20H" or "INT 21H function 00H" to terminate
a COM program's execution.  It is deprecated in newer versions, with
the recommendation to use "INT 21H, function 4CH" instead.  That does
allow for a return code as well.

HTH,

Steve N.

bugthis

Quote from: FORTRANS on May 02, 2023, 09:43:19 PM
....
In a
COM program the CS register points to the start of the PSP.  In an EXE
program the CS register points to where you told MS-DOS the entry point
of your program is.  ...

Thank you very much. That's what i wanted to know.

The reason I ask was the following realization:
If I gave DEBUG an EXE program as a parameter and started DEBUG with the EXE, then the IP pointed to the offset address 0000h.
However, when I started DEBUG without specifying an EXE file, the IP pointed to 0100h.

I therefore i wondered if I wanted to modify a loaded EXE file with Debug on the fly with the "A" command, then i am writing probably around in the PSP.
That was the reason why I wanted to compile the assembler file in a way to start at address 0100h.

But now this is clear to me. When using an EXE file, the PSP is always before the first instruction of the code, no matter if the IP is pointing to 0000h or 0100h, right?

FORTRANS

Hi,

Quote from: bugthis on May 09, 2023, 12:33:51 PM
But now this is clear to me. When using an EXE file, the PSP is always before the first instruction of the code, no matter if the IP is pointing to 0000h or 0100h, right?

   In an EXE program the CS:IP points to the entry point of your program.
In my template for a 16-bit program I have the stack segment first, the
data segment next, and the code segment last.  So in that case, the first
byte after the PSP is in the stack area.  If you have the code first in your
program, and you have the entry point at the start of your code it will
have the IP as 0000H and pointing to just past the PSP.  You can modify
things so it is different, but that is usually uncommon and unnecessary.

   COM programs always have the entry point at 0100H.

Cheers,

Steve N.