NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: ben321 on November 20, 2015, 09:22:49 AM
-
So I'm using NASM along with ALink to make a DOS EXE file (GoLink doesn't let you do that). So here's what I have in my assembly code so far.
SEGMENT stack STACK
resb 64
SEGMENT text CLASS=CODE
GLOBAL main
main:
nop
nop
nop
ret
I'm using the debugger version of DOSBox (great for debugging DOS EXEs like OllyDbg does with Win32 EXEs). I notice something, the stack really is only 64 bytes in size. I only used this code because according to http://www.nasm.us/doc/nasmdoc8.html you only need to include a stack segment in the EXE file to make the linker happy. I want a larger stack (at least 1 kilobyte). So I decided to turn the "resb 64" into "resb 1024". Problem is this adds 1 kilobyte to the size of the EXE file. How do I set the size of the DOS EXE's stack in the ASM code, without making my EXE file bigger? And isn't the "resb" command supposed to only reserve the RAM, not change the size of the EXE file? I need some help here.
-
I don't have the possiblity to compile anything, but you have to define the SS and SP segments in an exe file. Maybe this can help, but I cannot prove it.
SEGMENT Datos
; Aquí se ponen los datos
SEGMENT Pila STACK ; Definimos el segmento de pila
RESB 256 ; de 256 bytes de longitud
InicioPila:
SEGMENT Codigo ; Definimos el segmento de código
..start: ; Informamos que aquí empieza el código
MOV AX, Pila ; Metemos en SS el inicio de la pila
MOV SS, AX
MOV SP, InicioPila ; y en SP el puntero al final de la pila
MOV AX, Datos ; Metemos en DS el segmento de datos
MOV DS, AX
; Aquí codificamos las instrucciones del programa
MOV ah, 4ch
INT 21h ; Salimos al DOS
; Aquí podemos poner el resto de los procedimientos y macros
-
How do I set the size of the DOS EXE's stack in the ASM code, without making my EXE file bigger?
Put it last.
The obsolete "OMF" (object module format) format has no "named" segments - you can name them anything you want. Ordinarily, Nasm would complain about the "resb" family in any section but .bss, but in "-f obj - since there isn't a .bss section - you can use it anywhere without complaint... but it only works as expected if it comes last.
; nasm -f obj omftest.asm
; alink -oEXE omftest.obj
segment kode class=code
..start:
mov ax, kode
mov ds, ax
mov dx, msg
mov ah, 9
int 21h
mov ax, 4C00h
int 21h
segment data
msg db "hello museum!$"
segment stack stack
resb 1000h
That assembles and links without complaint (126 bytes). Dunno if it runs or not. I think it should. DosBox has always given me trouble. One of these days I should wrestle with it again, but I'm kinda headed in the other direction...
Best,
Frank
-
How do I set the size of the DOS EXE's stack in the ASM code, without making my EXE file bigger?
Put it last.
The obsolete "OMF" (object module format) format has no "named" segments - you can name them anything you want. Ordinarily, Nasm would complain about the "resb" family in any section but .bss, but in "-f obj - since there isn't a .bss section - you can use it anywhere without complaint... but it only works as expected if it comes last.
; nasm -f obj omftest.asm
; alink -oEXE omftest.obj
segment kode class=code
..start:
mov ax, kode
mov ds, ax
mov dx, msg
mov ah, 9
int 21h
mov ax, 4C00h
int 21h
segment data
msg db "hello museum!$"
segment stack stack
resb 1000h
That assembles and links without complaint (126 bytes). Dunno if it runs or not. I think it should. DosBox has always given me trouble. One of these days I should wrestle with it again, but I'm kinda headed in the other direction...
Best,
Frank
Thanks for the help. That got it working.