Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

Basic 8086 Programming Concepts

• In assembly language programming, coding is done in symbolic language (called


mnemonics). The mnemonic specifies the operation to be done.

• We also call it an opcode that stands for operation code – i.e., the code which
specifies the operation to be performed.

• Opcodes operate on data, which are called the operands.

• The combination of the opcode and the operand forms an instruction.


General Features of 8086 Instructions
• Most instructions have two operands i.e., the destination and the source. These
can be registers or memory operands. However, both operands cannot be
memory operands. Some instructions can also use immediate data as the source
operand.

• Certain instructions have only one operand mentioned which is either the
destination or the source. These can be register or memory operands, but not
immediate data.

• There are instructions that have no operands explicitly mentioned in the


instructions. In that case, some register is implicit in the usage of these
instructions.
Functionalities to which the Instructions Belong
• Data Transfer Instructions

• Branch Instructions

• Arithmetic Instructions

• Logical Instructions

• Shift and Rotate Instructions

• String Instructions

• I/O Instructions
Data Transfer Instructions
We will come back to these later
• MOV – Move
• Usage: MOV Destination, Source
• MOV AX, 100H
• MOV AX, CX
• MOV AL, AH
• MOV AX, [BX]
• MOV COST, DX
• MOV AL, ‘W’
Arithmetic Instructions

• ADD dst, src


• ADC dst, src
• SUB dst, src
• DEC dst
• CMP dest, src
Branching Instructions
• Unconditional Jump
JMP Label

• Conditional Jump
JNZ Label
JNC Label
Simple Program 1
• Store two numbers in registers and put their sum in a third register.
Simple Program 2
• Add two numbers. If the sum is greater than some X, make register
CX=0, else make CX=1.
How to use Memory Locations-Assembly Process,
Instructions and Directives, Memory Models
• When we want to write and execute an ALP, we first type it using an editor. Then
we assemble, link and run it.
• An assembler translates this symbolic language to machine code which the
processor will understand.
• An assembly language program contains pseudo-instructions (directives) along
with instructions.
• Instructions get translated to machine codes, but directives do not. i.e.,
instructions produce executable code, but directives do not. They direct the
assembler to perform in certain ways that we would like it to.
• The directives perform as ‘help’ for the assembler for deciding certain
other aspects of the assembly process
• Different popular assemblers are NASM, FASM, MASM, TASM and HLA.
Memory Models

• To write programs, we know we have to define segments, which means that the
segment registers must be initialized.
• Assemblers offer shortcuts which help to make programming simple. These are
called the dot models. They have the format:
.MODEL MODEL_NAME
• The different models tell the assembler how to use segments and to provide
sufficient space for the object code.
• The simplest of these are the tiny model and the small model.
• The tiny model is used when code, data and stack will all fit into one segment
with a maximum size of 64 K.
• The small model can have one data segment and one code segment
each of which has a maximum size of 64 K.
The Tiny Model
• Let us understand this model with the help of a code snippet. First without memory variables

• .EXIT is a shortcut which is actually transformed to two instructions:


MOV AH, 4CH
INT 21H
• These two instructions terminate program execution and bring control back to DOS. END is
a directive. It tells the assembler to stop reading, as there are no instructions beyond this.
Tiny Model – List File after Assembling
Tiny Model with Memory Variables
First the Directives
Tiny Model with Memory Variables
Small Model – One Data Segment and One Code
Segment

The Assembler inserts instructions to initialize the segment registers except CS which is done by OS
The DUP Directive
• This directive is used to replicate a given number of characters.

• NUMS DB 10 DUP(0) fills up with 0s the 10-byte locations starting with


the label NUMS.

• STARS DB 5 DUP(‘#’) fills up 5-byte locations starting at location STARS,


with the ASCII value of the character #.
The EQU Directive
• This directive allows us to equate names to constants. The assembler
just replaces the names by the values mentioned.
The ORG Directive
• ORG is a directive which means
‘origin’. In the context of assembly
language programming, it can
change the location of storage of
data or code in memory i.e., the
programmer gets the freedom to
decide the offset of data/code
when it is stored.

• The format is ORG d16, where d16


means a 16-bit displacement.
The Full Segment Model
• In the simplified memory model, it
is left to the loader software to
initialize the segment registers.
• In the traditional model, we use
directives to define segments, and
instructions to initialize the
segment registers. This is called the
Full Segment definition.
• The CS and SS registers are
automatically initialized by the
loader, but the DS and ES (if the
extra segment is being used) will
have to be initialized by the
programmer.

You might also like