Articles Details
Type: programming theory
Subject: Computer Architectures
Background: 8086 MicroProcessor architectiore, basic programing knowledges
8086 Assembly programming means develop programs in 8086 assembly programming language. 8086 Assembly is a low level programming language. The developer have to deal with object of the processor like segment and register. In this article, we will see what are the basic elements of this language and the structure of a simple program.
Basic elements of 8086 assembly programming language
8086 assembly programming language instructions
Like we know instruction are the lines of a program that means an action for the computer to execute.
In 8086, a normal instruction is made by an operation code and sometimes operands.
Structure:
OperationCode [Operand1 [, Operand2]]
Operations
the operation are usually logic or arithmetic, but we can also find some special operation like the Jump (JMP) operation.
JUMP operation is an operation that stop the linear execution of the code and indicate the next instruction to execute. It is more complex because it can be unconditional or conditional on the result of some previous operations or on flag value.
Operands
Operands are the parameters of the operation in the instruction. They can be use in 3 way:
- Immediate
This means a direct access of a variable that have been declared in the program.
- Register
Here we use the content of a register to be a parameter.
- Memory
Here we access to the content of a specific part of the memory using a pointer.
Special instructions
Now we will see how to declare a variable and some interrupt instruction.
Declaration
In 8086, we need to declare the name of the variable, the size of the variable and it value.
Structure:
VariableName SizeDirective value [ dup (num)]
VariableName : name of your variable.
SizeDirective: word system to define the size, DB will define byte and DW will define a Word(2 byte).
value is your variable value
dub: a system word that means duplicate, used for vector.
num: number of time you duplicate, the size of your vector.
Interrupt
Interrupt calls a sub routine of the system to be executed. we will see 2 simple interrupt:
1 – read character from standard input, result is stored in AL.
MOV AH,01h INT 21h
2 – write character to standard output, DL = character to write.
MOV AH,02h INT 21h
8086 assembly programming language directives
from Wikipedia, we can read that “Assembly directives, also called … pseudo-operations …, are instructions that are executed by an assembler at assembly time, not by a CPU at run time. The names of pseudo-operations often start with a dot to distinguish them from machine instructions”
Examples: .MODEL , .STACK , .CODE
8086 assembly program template
Let’s look at an example to understand the structure of a program:
; This is a comment ; 8086 Template example: Hello World ; contant declaration section ; directives for the compiler .MODEL small .STACK .DATA ; variable declaration section message db "Hello World $" ; code section .CODE .STARTUP ; interrup to print a string with $ at the end mov ah,09h mov dx,offset message int 21h .EXIT END ; end of the program
References and Learning more
Reference 1
Reference 2
Reference 3
Reference 4
Reference 5