Home > OS >  not adding the stack bytes to the .exe file with MASM 5.0
not adding the stack bytes to the .exe file with MASM 5.0

Time:05-06

I'm writing two assembly files for DOS:

hm2.asm:

.8086 
DGROUP group _DATA, STACK  ; Required by MASM 3.0 and 4.0. 
 
; MASM 4.0 doesn't support USE16 (but MASM >=5.0 does). 
_TEXT segment word public 'CODE' 
assume cs:_TEXT, ds:DGROUP, ss:STACK 
main proc 
mov ax, DGROUP  ; Initialize DS. 
mov ds, ax 
mov ah, 9  ; DOS Function call to print a message. 
mov dx, offset message 
int 21h 
mov ax, 4c00h  ; DOS Function call to exit back to DOS. 
int 21h 
main endp 
_TEXT ends 
 
_DATA segment word public 'DATA' 
message db "Hello, World!", 0dh, 0ah, '$' 
_DATA ends 
 
STACK segment para stack 'STACK' 
db 100h dup (?) 
STACK ends 
 
end main 

hm3.asm:

.8086 
.model small 
.stack 100h 
.data 
message db "Hello, World!", 0dh, 0ah, '$' 
.code 
main proc 
mov ax, @data  ; Initialize DS. 
mov ds, ax 
mov ah, 9  ; DOS Function call to print a message. 
mov dx, offset message 
int 21h 
mov ax, 4c00h  ; DOS Function call to exit back to DOS. 
int 21h 
main endp 
end main 

I want these to be identical when compiled by Microsoft Macro Assembler 5.00 masm.exe and then linked to an .exe file with the corresponding link.exe . However, hm2.exe is about 256 == 100h bytes larger than hm3.exe, because it contains 0 bytes for the STACK. How do I get rid of these 0 bytes without using .model and .stack, thus being compatible with Microsoft Macro Assembler 4.00 and earlier?

CodePudding user response:

I found a copy of the MASM 3.00 manual here. On page 3-2 there is an example program that looks like this

 .8086

DATA segment ; Program Data Segment
STRING db "Hello .", 13, 10, "$"
DATA ends

CODE segment ; Program Code Segment
 assume cs :CODE, ds :DATA
START: ; Program Entry Point
 mov ax, seg DATA
 mov ds, ax
 mov dx, offset STRING
 mov ah, 9
 int 21h
 mov ah, 4ch
 int 21h
CODE ends

STACK segment stack ; Program Stack Segment
 assume ss :STACK
 dw 64 dup(?)
STACK ends

 end START

I was able to assemble and link this to an exe of 640 bytes. When I increased the stack size (from 64 to 1024) the exe size didn't change, from which I assume that the linker is not padding out unitialized stack bytes in the image. If you compare the example program to yours, maybe that'll help you figure it out.

Possibly the answer is to remove the DGROUP directive.

  • Related