Experiment No1-4
Experiment No1-4
1
Addition
Aim:- Write assembly language program to perform 8 bit and 16 bit addition
Objective: To add 8 bit and 16 bit binary numbers using addition rules for binary arithmetic
instruction.
Software: 8086 Emulator
Theory: The 8086 has four groups of the user accessible internal registers. They are
general purpose registers
Segment registers
pointer and index registers
Flag register
Segment register:
• • Code segment (CS) is a 16-bit register containing address of 64 KB segment with processor
instructions. The processor uses CS segment for all accesses to instructions referenced by
instruction pointer (IP) register. CS register cannot be changed directly. The CS register is
automatically updated during far jump, far call and far return instructions.
• • Stack segment (SS) is a 16-bit register containing address of 64KB segment with program
stack. By default, the processor assumes that all data referenced by the stack pointer (SP) and base
pointer (BP) registers is located in the stack segment. SS register can be changed directly using POP
instruction.
• • Data segment (DS) is a 16-bit register containing address of 64KB segment with program
data. By default, the processor assumes that all data referenced by general registers (AX,
• BX, CX, DX) and index register (SI, DI) is located in the data segment. DS register can be
changed directly using POP and LDS instructions.
• • Extra segment (ES) is a 16-bit register containing address of 64KB segment, usually with
program data. By default, the processor assumes that the DI register references the ES segment in
string manipulation instructions. ES register can be changed directly using POP and LES instructions
Flag Register
Flags is a 16-bit register containing nine 1-bit flags. 06 flags are status flags and 3 are Control Flags
• •Overflow Flag (OF) - set if the result is too large positive number, or is too small negative
number to fit into destination operand.
• •Direction Flag (DF) - if set then string manipulation instructions will auto-decrement index
registers. If cleared then the index registers will be auto-incremented.
• •Interrupt-enable Flag (IF) - setting this bit enables maskable interrupts.
• •Single-step Flag (TF) - if set then single-step interrupt will occur after the next instruction.
• •Sign Flag (SF) - set if the most significant bit of the result is set.
• •Zero Flag (ZF) - set if the result is zero.
• •Auxiliary carry Flag (AF) - set if there was a carry from or borrow to bits 0-3 in the AL
register.
• •Parity Flag (PF) - set if parity (the number of "1" bits) in the low-order byte of the result is
even.
• •Carry Flag (CF) - set if there was a carry from or borrow to the most significant bit
• during last result calculation.
MOV AX,0000H
MOV DS,AX
MOV AX,[1030H]
ADD AL,[1032H]
MOV [1034H],AX
INT
Observations:-
Result: -
[1030H]=05
[1032H]=05
[1034H]=0A.
Experiment No.2
Subtraction
Aim:- Write assembly language program to perform 8 bit and 16 bit subtraction
Objective: To subtract 8 bit and 16 bit binary numbers using subtraction rules for binary arithmetic
instruction.
Software: 8086 Emulator
Theory: 8086 ADDRESSING MODES
Immediate addressing mode:
In this mode, 8 or 16 bit data can be specified as part of the instruction. OP Code Immediate
Operand
Example 1 : MOV CL, 03 H
Moves the 8 bit data 03 H into CL
Example 2 : MOV DX, 0525 H
Moves the 16 bit data 0525 H into DX
In the above two examples, the source operand is in immediate mode and the destination operand
is in register mode. A constant such as “VALUE” can be defined by the assembler EQUATE directive
such as VALUE EQU 35H
Example : MOV BH, VALUE
Used to load 35 H into BH
Register addressing mode :
The operand to be accessed is specified as residing in an internal register of 8086.Internal registers
can be used as a source or destination operand, however only the data registers can be accessed as
either a byte or word.
Example 1 : MOV DX (Destination Register) , CX (Source Register)
Which moves 16 bit content of CS into DX.
Example 2 : MOV CL, DL
Moves 8 bit contents of DL into CL
MOV BX, CH is an illegal instruction.
• • The register sizes must be the same.
Result in CH
SUB AX, 3427H Subtract immediate number 3427H from AX
SBB BX, [3427H] Subtract word at displacement 3427H in DS and content of CF
Decrement Instruction
DEC – DEC Destination
This instruction subtracts 1 from the destination word or byte. The destination can be a register or a
memory location. AF, OF, SF, PF, and ZF are updated, but CF is not affected. This means that if an 8-
bit destination containing 00H or a 16-bit destination containing 0000H is decremented, the result
will be FFH or FFFFH with no carry (borrow).
DEC CL Subtract 1 from content of CL register
DEC BP Subtract 1 from content of BP register
DEC BYTE PTR [BX] Subtract 1 from byte at offset [BX] in DS.
DEC WORD PTR [BP] Subtract 1 from a word at offset [BP] in SS.
DEC COUNT Subtract 1 from byte or word named COUNT in DS.
Decrement a byte if COUNT is declared with a DB;
Decrement a word if COUNT is declared with a DW.
Increment instruction
INC – INC Destination
The INC instruction adds 1 to a specified register or to a memory location. AF, OF, PF, SF, and ZF are
updated, but CF is not affected. This means that if an 8-bit destination containing FFH or a 16-bit
destination containing FFFFH is incremented, the result will be all 0’s with no carry.
INC BL Add 1 to contains of BL register
INC CX Add 1 to contains of CX register
INC BYTE PTR [BX] Increment byte in data segment at offset contained in BX.
INC WORD PTR [BX] Increment the word at offset of [BX] and [BX + 1] in the data segment.
INC TEMP Increment byte or word named TEMP in the data segment.
Observations:-
Result: -
[1030H]=5468
[1032H]=2357
[1034H]=3111
Conclusion: Thus the addressing modes are studied and the 8-bit and 16-bit subtraction is
implemented
Experiment No.3
Multiplication
Aim:- Write assembly language program to perform 8 bit and 16 bit multiplication
Objective: To study string related operations with the help of string instructions.
To use Multiplication instruction for 8 bit and 16 bit numbers.
Software: 8086 Emulator
Theory:
MUL – MUL Source
This instruction multiplies an unsigned byte in some source with an unsigned byte in AL register or
an unsigned word in some source with an unsigned word in AX register. The source can be a register
or a memory location. When a byte is multiplied by the content of AL, the result (product) is put in
AX. When a word is multiplied by the content of AX, the result is put in DX and AX registers. If the
most significant byte of a 16-bit result or the most significant word of a 32-bit result is 0, CF and OF
will both be 0’s. AF, PF, SF and ZF are undefined after a MUL instruction.
If you want to multiply a byte with a word, you must first move the byte to a word location such as
an extended register and fill the upper byte of the word with all 0’s. You cannot use the CBW
instruction for this, because the CBW instruction fills the upper byte with copies of the most
significant bit of the lower byte.
MUL BH Multiply AL with BH; result in AX
MUL CX Multiply AX with CX; result high word in DX, low word in AX
MUL BYTE PTR [BX] Multiply AL with byte in DS pointed to by [BX]
MUL FACTOR [BX] Multiply AL with byte at effective address FACTOR [BX], if it is declared as
type byte with DB. Multiply AX with word at effective address FACTOR [BX], if it is declared
as type word with DW. MOV AX, MCAND_16 Load 16-bit multiplicand into AX
MOV CL, MPLIER_8 Load 8-bit multiplier into CL
MOV CH, 00H Set upper byte of CX to all 0’s
MUL CX AX times CX; 32-bit result in DX and AX
MOV AX,0000H
MOV DS,AX
MOV AL,[1030H]
MOV BL,[1032H]
MUL BL
MOV [1034H],AX
INT
Observations:-
Result:
[1030H]=02
[1032H]=02
[1034H]=04
Observations:-
Result:-
[1030H]=0102
[1032H]=0102
[1034H]=0104.
Conclusion: Thus the string instructions are studied and multiplication for 8 bit and 16 bit.
Experiment No.4
Division
Aim:- Write assembly language program to perform 8 bit and 16 bit division.
Objective: Describe the conditional and unconditional jump instructions.
To study and implement the division instructions.
Software: 8086 Emulator
Theory:
DIV – DIV Source
This instruction is used to divide an unsigned word by a byte or to divide an unsigned double word
(32 bits) by a word. When a word is divided by a byte, the word must be in the AX register. The
divisor can be in a register or a memory location. After the division, AL will contain the 8-bit
quotient, and AH will contain the 8-bit remainder. When a double word is divided by a word, the
most significant word of the double word must be in DX, and the least significant word of the
double word must be in AX. After the division, AX will contain the 16-bit quotient and DX will
contain the 16-bit remainder. If an attempt is made to divide by 0 or if the quotient is too large to fit
in the destination (greater than FFH / FFFFH), the 8086 will generate a type 0 interrupt. All flags are
undefined after a DIV instruction.
If you want to divide a byte by a byte, you must first put the dividend byte in AL and fill AH with all
0’s. Likewise, if you want to divide a word by another word, then put the dividend word in AX and
fill DX with all 0’s.
DIV BL Divide word in AX by byte in BL; Quotient in AL, remainder in AH
DIV CX Divide down word in DX and AX by word in CX;
Quotient in AX, and remainder in DX.
DIV SCALE [BX] AX / (byte at effective address SCALE [BX]) if SCALE [BX] is of type
byte; or (DX and AX) / (word at effective address SCALE[BX]
if SCALE[BX] is of type word
MOV AX,0000H
MOV DS,AX
MOV AX,[1030H]
MOV BL,[1032H]
DIV BL
MOV [1034H],AX
INT
Observation:-
Result:-
[1030H]=08
[1032H]=04
[1034H]=02
MOV AX,0000H
MOV DS,AX
MOV AX,[1030H]
MOV BX,[1032H]
DIV BX
MOV [1034H],AX
INT
Observation:-
Result:-
[1030H]=08
[1032H]=02
[1034H]=04.