You are on page 1of 2

Simplified and Conventional segment directives

- initialize the memory model before defining any segments


- the format is .model memory-model
- the memory model may be Tiny, Small, Medium, Compact, Large, Huge or Flat
- Small. Code in one segment (<= 64KB), data in one segment (<=64KB)
- The formats for the directives that define the stack, data and code segments are:
.stack [size]
.data
.code

- Each of these directives causes the assembler to generate the required SEGMENT statement and its
matching ENDS
- .stack sets up the stack
- The default stack size is 1024 bytes, which you may override
- If you want to change the default size, specify the size as its operand
- .data defines the beginning of a data segment
- All data definitions should be put after this directive
- .code ends a data segment and starts a code segment
- Place all executable statements for the procedure after this directive

Declaring data (Variables) inside the data segment


- the ff. code is a data declaration
msg db "hello world",13,10, "$"
- the variable name is msg
- db stands for define byte
- the bytes defined are “hello world”, 13, 10 and “$”
- 13 is the ascii code for carriage return
- 10 is the ascii code for line feed
- The combination of the two is equivalent to the new line (\n) in C language
- “$” is used as the terminator
- Each character in your variable is equivalent to 1 byte
- The address of your first character is usually saved in the address DS:0000h, the next DS:0001h and so
on.
- If you have more than 1 variable, the first character of the second variable is stored at the next byte after
the last byte occupied by the last character of the first variable

mov instruction
- transfers data referenced by the address of the second operand to the address of the first operand
- the sending (2nd operand) field is unchanged
- the operands must agree in size
- valid operands are: between two registers, between a register and a memory, immediate data to a register
or memory
Initialize Address of the Data Segment in DS register
mov ax, @data
mov ds, ax
- the code above initializes the DS register with the address of the data segment

lea (load effective address)


- loads an offset address into a register
- an equivalent is the mov with offset operator
- ex. lea dx, msg1 is equivalent to mov ds, offset msg1
printing string
- the int 21h is a common DOS interrupt that uses a function code in the ah register to specify an action to
be performed
- the int 21h function 09h is used to display string into the screen
- it requires definition of a display string in the data area, immediately followed by a dollar sign ($ or 24h)
- the dollar sign is used to end the display
- set function 09h in ah
- issue an int 21h instruction
ex. mov ah , 09h
int 21h
terminating the program
- int 21h function 4ch is used to end a program execution and return to DOS
- set function 4ch in ah
- issue an int 21h instruction
- ex. mov ah, 4ch
- int 21h
ending a procedure
- the ff. format is used to close a procedure
- [proc name] endp
ending the program
- the ff. format is used to end a program
- end [proc name]

how to assemble, link and execute an assembly program


1. on the c:\ promt, type the ff: tasm\bin\tasm file_source\file.asm, file_destination\file.obj
2. on the c:\ promt, type the ff: tasm\bin\tlink file_source\file.obj, file_destination\file.exe
3. on the c:\ promt, type the ff: file_source\file.exe

You might also like