Module:2 Assembly Language Programming and
Tools:
Addressing modes and Instruction Set, Assembler
Directives and Operators, Introduction to emu8086
emulator and MASM assembler, Assembly Language
example programs.
ADDRESSING MODES
• The way of specifying data to be operated by an instruction is known
as addressing modes. This specifies that the given data is an immediate
data or an address. It also specifies whether the given operand is
register or register pair.
• Immediate addressing mode: The addressing mode in which the data
operand is a part of the instruction itself is known as immediate
addressing mode.
• Example: MOV AX, 1234h - copies value 1234h into AX
• Register mode: In this type of addressing mode both the operands are
registers. Or It means that the register is the source of an operand for
an instruction.
• Example: MOV AX, BX - moves the contents of register BX into register AX
• Displacement or direct mode: In this type of addressing mode the
effective address is directly given in the instruction as displacement.
• Example: MOV AX, [1234h] - displaces register AX with the data stored at
the memory location 1234h.
• Register indirect addressing mode: This addressing mode allows
data to be addressed at any memory location through an offset address
held in any of the following registers: BP, BX, DI & SI.
• Example: MOV AX, [BX] - copies the data pointed to by a 16-bit signed offset
relative to a 16-bit register with data type of pointer into a 16-bit register with
data type of integer.
• Indexed addressing mode: In this addressing mode, the operands offset
address is found by adding the contents of SI (Index register) or DI
(displacement) register and 8-bit/16 bit displacements.
• Example: MOV AX, [BX+SI] - Moves the data located at the address formed by
adding the contents of BX and SI registers into register AX.
• Based Addressing: Like indexed addressing, but the base address is added to
the offset in the instruction.
• Example: MOV AX, [1234h+SI] – loads register AX with data from the address that is
1234h added with SI.
• Based Indexed Addressing: Combines based and listed addressing modes, in
which an offset is introduced to a base deal with stored in a sign in, and an
index sign in is used to in addition regulate the address.
• Example: MOV AX, [BX DI 10h] - movements the facts positioned on the cope with
shaped through adding the contents of BX, DI, and an instantaneous offset of 10h into
sign up AX.
INSTRUCTION SET
• The 8086 instructions are categorized into the following main types
• Data transfer instructions
• Arithmetic instructions
• Program control transfer instructions
• Machine control instructions
• Shift/rotate instructions
• Flag manipulation instructions
• String instructions
• DATA COPY /TRANSFER INSTRUCTIONS:
• These type of instructions are used to transfer data from source
operand to destination operand. All the store, load, move, exchange
input and output instructions belong to this category.
• MOV (Move)
• Syntax: MOV destination, supply
• Description: The MOV preparation transfers statistics from a supply operand
to a destination operand. The source and destination operands may be
registers, memory places, or instantaneous values.
• Example: MOV AX, BX - Moves the contents of sign in BX into sign up AX.
• PUSH instruction:
• The PUSH instruction decrements the stack pointer by two and copies
the word from source to the location where stack pointer now points.
Here the source must of word size data. Source can be a general
purpose register, segment register or a memory location.
• The PUSH instruction first pushes the most significant byte to sp-1,
then the least significant to the sp-2.
• Push instruction does not affect any flags.
• Example:- PUSH CX ; Decrements SP by 2, copy content of CX to the stack
(figure shows execution of this instruction)
• PUSH DS ; Decrement SP by 2 and copy DS to stack
• POP instruction:
• The POP instruction copies a word from the stack location pointed by
the stack pointer to the destination. The destination can be a General
purpose register, a segment register or a memory location. Here after
the content is copied the stack pointer is automatically incremented by
two.
• The execution pattern is similar to that of the PUSH instruction.
• Example: POP CX; Copy a word from the top of the stack to CX and
increment SP by 2.
• IN & OUT instructions:
• The IN instruction will copy
data from a port to the
accumulator. If 8 bit is read the
data will go to AL and if 16 bit
then to AX.
• Similarly OUT instruction is
used to copy data from
accumulator to an output port.
Both IN and OUT instructions
can be done using direct and
indirect addressing modes.
• XCHG Instruction:
• The XCHG instruction
exchanges contents of the
destination and source. Here
destination and source can be
register and register or register
and memory location, but XCHG
cannot interchange the value of 2
memory locations.
• XCHG Destination, Source.
Arithmetic and logical instruction
• All the instructions performing arithmetic, logical, increment,
decrement, compare and ASCII instructions belong to this category.
• ADD instruction:
• Add instruction is used to add the current contents of destination with
that of source and store the result in destination. Here we can use
register and/or memory locations.
• ADD Destination, Source
• ADC: ADD WITH CARRY
• This instruction performs the same operation as ADD instruction, but
adds the carry flag bit (which may be set as a result of the previous
calculation) to the result. All the condition code flags are affected by
this instruction.
• SUB instruction:
• SUB instruction is used to subtract the current contents of destination
with that of source and store the result in destination. Here we can use
register and/or memory locations. AF, CF, OF, PF, SF, and ZF flags are
affected
• SUB Destination, Source
• SBB: SUBTRACT WITH BORROW:
• To subtract with borrow instruction subtracts the source operand and the
borrow flag (CF) which may reflect the result of the previous calculations,
from the destination operand. Subtraction with borrow, here means subtracting
1 from the subtraction obtained by SUB, if carry (borrow) flag is set.
• The result is stored in the destination operand. All the flags are affected
(condition code) by this instruction.
• CMP: COMPARE:
• The instruction compares the source operand, which may be a register or an
immediate data or a memory location, with a destination operand that may be
a register or a memory location.
• For comparison, it subtracts the source operand from the destination operand
but does not store the result anywhere. The flags are affected depending upon
the result of the subtraction.
• INC & DEC instructions:
• INC and DEC instructions are used to increment and decrement the content
of the specified destination by one. AF, CF, OF, PF, SF, and ZF flags are
affected.
• AND instruction:
• This instruction logically ANDs each bit of the source byte/word with the
corresponding bit in the destination and stores the result in destination. The
source can be an immediate number, register or memory location, register can
be a register or memory location.
• OR instruction:
• This instruction logically ORs each bit of the source byte/word with the
corresponding bit in the destination and stores the result in destination. The
source can be an immediate number, register or memory location, register can
be a register or memory location.
400 MOV SI, 500 SI=500
403 MOV DI, 600 DI=600
406 MOV AL, [SI] AL<-[SI]
408 INC SI SI=SI+1
409 MOV BL, [SI] BL<-[SI]
40B MUL BL AX=AL*BL
40D MOV [DI], AX AX->[DI]
40F HLT END