Format C:
31.08.2002, 02:16
moin
folgendes Tutorial in der Doc von NASM :
An example of a NASM source file which can be assembled
to a .OBJ file and linked on its own to a .EXE is given here.
It demonstrates the basic principles of defining a stack,
initialising the segment registers, and declaring a start point.
This file is also provided in the test subdirectory of the
NASM archives, under the name objexe.asm.
segment code
..start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,stacktop
This initial piece of code sets up DS to point to the data segment,
and initialises SS and SP to point to the top of the provided
stack. Notice that interrupts are implicitly disabled for one
instruction after a move into SS, precisely for this situation, so
that there's no chance of an interrupt occurring between the
loads of SS and SP and not having a stack to execute on.
Note also that the special symbol ..start is defined at the
beginning of this code, which means that will be the entry point
into the resulting executable file.
mov dx,hello
mov ah,9
int 0x21
mov ax,0x4c00
int 0x21
segment data
hello: db 'hello, world', 13, 10, '$'
The data segment contains the string we want to display.
segment stack stack
resb 64
stacktop:
Frage 1: warum wird hier der Stack selbst angelegt ? Es wird doch in diesen kleinen Prog kein Byte an Stack gebraucht ?
Frage 2: Muß man in einen Assembler Programm die größe des Stacks selber festlegen ? Ich dachte immer das macht alles der Linker
folgendes Tutorial in der Doc von NASM :
An example of a NASM source file which can be assembled
to a .OBJ file and linked on its own to a .EXE is given here.
It demonstrates the basic principles of defining a stack,
initialising the segment registers, and declaring a start point.
This file is also provided in the test subdirectory of the
NASM archives, under the name objexe.asm.
segment code
..start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,stacktop
This initial piece of code sets up DS to point to the data segment,
and initialises SS and SP to point to the top of the provided
stack. Notice that interrupts are implicitly disabled for one
instruction after a move into SS, precisely for this situation, so
that there's no chance of an interrupt occurring between the
loads of SS and SP and not having a stack to execute on.
Note also that the special symbol ..start is defined at the
beginning of this code, which means that will be the entry point
into the resulting executable file.
mov dx,hello
mov ah,9
int 0x21
mov ax,0x4c00
int 0x21
segment data
hello: db 'hello, world', 13, 10, '$'
The data segment contains the string we want to display.
segment stack stack
resb 64
stacktop:
Frage 1: warum wird hier der Stack selbst angelegt ? Es wird doch in diesen kleinen Prog kein Byte an Stack gebraucht ?
Frage 2: Muß man in einen Assembler Programm die größe des Stacks selber festlegen ? Ich dachte immer das macht alles der Linker