Monday 24 December 2012

8086 Assembly language program structure


Program Structure

I won't say there is any defined pattern or structure an assembly language program(ALP) should appear unlike what we have in some high level languages but i'll say this is a very good way to start.

TITLE ……..
.MODEL ...
.STACK
.DATA          ;Begining of data segment.
…………..
…………..
.CODE          ;Begining of code segment.
start:              ;Indicates the beginning of instructions.
......
......

Main PROC  ;Begining of procedure (if neccessary)
……………
…………..
Main ENDP ;End of procedure.

END start         ;End of instruction.

Keywords

TITLE: identifies the program listing title. Any text typed to the right side of the directive is printed at the top of each page in the listing file.
.MODEL: selects a standard memory model for the programs.
.STACK: sets the size of the program stack which may b any size up to 64kb.
.CODE: identifies the part of the program that contains instructions .
PROC: creates a name and a address for the beginning of a procedure.
ENDP: indicates the end of the procedure.
.DATA: all variables pertaining to the program are defined in the area following this directive called data segment.
END: terminates assembly  of the program. Any lines of text placed after this directive is ignored.

Example
Write an Assembly Language Program that uses a procedure to perform simple unsigned Multiplication.
The two 16 bit numbers are 1121H and 1301H.
Store the product in the location whose offset address is 8100H.

TITLE Multiplication

.MODEL Small
.STACK 100H
.DATA
Num1 DW 1121H
Num2 DW 1301H
.CODE
start:

CALL Main ;instruction to call procedure Main

Main PROC ;Beginning of procedure Main
MOV AX, num1 ;Bring the first number to AX
MOV BX, num2 ;Bring second
MUL BX ;Multiply the contents of AX and BX
mov BP, [8100H] ;Moves offset address to Base pointer
MOV [BP],AX ;store the result at 8100H

MOV AX,4C00H ;Return to DOS
INT 21H
Main ENDP ;End of procedure Main

END start

No comments: