A program has always the following general structure:
|Structure of an Assembly Language Program|
.model small ;Select a memory model
.stack stack_size ;Define the stack size
; Variable and array declarations
; Declare variables at this level
; Write the program main code at this level
; Always organize your program
; into procedures
end main ; To mark the end of the source file
The title directive is optional and specifies the title of the program.
Like a comment, it has no effect on the program. It is just used to make
the program easier to understant.
The Model directive:
The model directive specifies the total amount of memory the program would take.
In other words, it gives information on how much memory the assembler would
allocate for the program. This depends on the size of the data and the size of
the program or code.
Segments are declared using directives. The following directives
are used to specify the following segments:
Used to set aside storage for the stack
Stack addresses are computed as offsets into this segment
Use: .stack followed by a value that inicates the size of the stack
Used to set aside storage for variables.
Constants are defined within this segment in the program source.
Variable addresses are computed as offsets from the start of this segment
Use: .data followed by declarations of variables or defintions of constants.
The code segment contains executable instructions macros
and calls to procedures.
Use: .code followed by a sequence of program statements.
Here is how the "hello world" program would look like in assembly:
|The hello world program in Assembly|
greeting db 'hello world !',13,10,'$'
mov dx,offset greeting