0% found this document useful (0 votes)
201 views15 pages

Experiment No1-4

The document describes an experiment to perform 8-bit and 16-bit addition and subtraction in assembly language using the 8086 emulator. It discusses the 8086 registers including general purpose registers AX, BX, CX, DX and flags register. It provides examples of addition instructions like ADD and ADC that add numbers and affect flags. The program provided performs an 8-bit addition by loading values into registers from memory locations, adding them, and storing the result back to memory. The observation shows the input, output and result of the addition program.

Uploaded by

abdullah noor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
201 views15 pages

Experiment No1-4

The document describes an experiment to perform 8-bit and 16-bit addition and subtraction in assembly language using the 8086 emulator. It discusses the 8086 registers including general purpose registers AX, BX, CX, DX and flags register. It provides examples of addition instructions like ADD and ADC that add numbers and affect flags. The program provided performs an 8-bit addition by loading values into registers from memory locations, adding them, and storing the result back to memory. The observation shows the input, output and result of the addition program.

Uploaded by

abdullah noor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Experiment No.

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

General Purpose Registers


• • AX : Accumulator register consists of two 8-bit registers AL and AH, which can be
combined together and used as a 16- bit register AX. AL in this case contains the low-order byte of
the word, and AH contains the high-order byte. Accumulator can be used for I/O operations and
string manipulation.
• • BX: Base register consists of two 8-bit registers BL and BH, which can be combined
together and used as a 16-bit register BX. BL in this case contains the low-order byte of the word,
and BH contains the high-order byte. BX register usually contains a data pointer used for based,
based indexed or register indirect addressing.
• • CX: Count register consists of two 8-bit registers CL and CH, which can be combined
together and used as a 16-bit register CX. When combined, CL register contains the low-order byte
of the word, and CH contains the highorder byte. Count register can be used in Loop, shift/rotate
instructions and as a counter in string manipulation,.
• • DX: Data register consists of two 8-bit registers DL and DH, which can be combined
together and used as a 16-bit register DX. When combined, DL register contains the low-order byte
of the word, and DH contains the highorder byte. Data register can be used as a port number in I/O
operations. In integer 32-bit multiply and divide instruction the DX register contains high-order
word of the initial or resulting number.

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

Pointer and Index Registers


• • Instruction Pointer (IP) is a 16-bit register that contains the offset address. IP is combined
with the CS to generate the address of the next instruction to be executed.
• • Stack Pointer (SP) is a 16-bit register pointing to program stack.
• • Base Pointer (BP) is a 16-bit register pointing to data in stack segment. BP register is
usually used for based, based indexed or register indirect addressing.
• • Source Index (SI) is a 16-bit register. SI is used for indexed, based indexed and register
indirect addressing, as well as a source data address in string manipulation instructions.
• • Destination Index (DI) is a 16-bit register. DI is used for indexed, based indexed and
register indirect addressing, as well as a destination data address in string manipulation
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.

Data Transfer Instructions


Data transfer is one of the most common tasks when programming in an assembly language. Data
can be transferred between registers or between registers and the memory. Immediate data can be
loaded to registers or to the memory. The transfer can be done on an octet or word. The two
operands must have the same size. Data transfer instructions don’t affect the condition indicators
(excepting the ones that have this purpose). They are classified as follows:
6. classical transfer instructions
7. address transfer instructions
8. condition indicator transfer instructions
9. input/output instructions (peripheral register transfers)

One of the Classical transfer instructions Include the following instruction:


MOV <d>, <s>
The MOV instruction is used to transfer a byte or a word of data from a source
operand to a destination operand. These operands can be internal registers of the
8086 and Meaning Format Operation Flags affected
storage
locations in
memory.
Mnemonic
MOV Move MOV D,S (S) → (D) None
Destination Source Example

Accumulator Memory MOV AX, TEMP

Register Register MOV AX, BX

Memory Register MOV COUNT [DI], CX

Register Immediate MOV CL, 04

Arithmetic Instructions : Addition


ADD – ADD Destination, Source
ADC – ADC Destination, Source
These instructions add a number from some source to a number in some destination and put the
result in the specified destination. The ADC also adds the status of the carry flag to the result. The
source may be an immediate number, a register, or a memory location. The destination may be a
register or a memory location. The source and the destination in an instruction cannot both be
memory locations. The source and the destination must be of the same type (bytes or words). If you
want to add a byte to a word, you must copy the byte to a word location and fill the upper byte of
the word with 0’s before adding. Flags affected: AF, CF, OF, SF, ZF.
ADD AL, 74H ; Add immediate number 74H to content of AL. Result in AL
ADC CL, BL ;Add content of BL plus carry status to content of CL(CL = CL+BL+Carry Flag)
ADD DX, BX ; Add content of BX to content of DX
ADD DX, [SI] ;Add word from memory at offset [SI] in DS to content of DX
Program:- /* 8 BIT ADDITION */

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.

Direct addressing mode :


The instruction Opcode is followed by an affective address, this effective address is directly used as
the 16 bit offset of the storage location of the operand from the location specified by the current
value in the selected segment register. The default segment is always DS.

Register indirect addressing mode :


The EA is specified in either pointer (BX) register or an index (SI or DI) register. The 20 bit physical
address is computed using DS and EA.
Example : MOV [DI], BX
register indirect
If [DS] = 5004, [DI] = 0020, [Bx] = 2456 PA=50060.
The content of BX(2456) is moved to memory locations 50060 H and 50061 H.,
Instructions:
SUB – SUB Destination, Source
SBB – SBB Destination, Source
These instructions subtract the number in some source from the number in some destination and
put the result in the destination. The SBB instruction also subtracts the content of carry flag from
the destination. The source may be an immediate number, a register or memory location. The
destination can also be a register or a memory location. However, the source and the destination
cannot both be memory location. The source and the destination must both be of the same type
(bytes or words). If you want to subtract a byte from a word, you must first move the byte to a
word location such as a 16-bit register and fill the upper byte of the word with 0’s. Flags affected:
AF, CF, OF, PF, SF, ZF.

 SUB CX, BX CX – BX; Result in CX


 SBB CH, AL Subtract content of AL and content of CF from content of CH. From BX
 SUB PRICES [BX], 04H Subtract 04 from byte at effective address PRICES [BX],
if PRICES is declared with DB; Subtract 04 from word at effective address PRICES [BX], if it is
declared with DW.
 SBB CX, TABLE [BX] Subtract word from effective address TABLE [BX]
and status of CF from CX.
 SBB TABLE [BX], CX Subtract CX and status of CF from word in memory at
effective address TABLE[BX].

 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.

Program:- /* 8 BIT SUBSTRACTION */


MOV AX,0000H
MOV DS,AX
MOV AL,[1030H]
MOV BL,[1032H]
SUB AL, BL
MOV [1034H],AX
INT
Observations:-
Result: -
[1030H]=08
[1032H]=02
[1034H]=06.

Program:- /* 16 BIT SUBSTRACTION */


MOV AX,0000H
MOV DS,AX
MOV AX,[1030H]
MOV BX,[1032H]
SUB AX,BX
MOV [1034H],AX
INT

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

Program:- /* 8 BIT MULTIPLICATION */

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

Program:- /* 16 BIT MULTIPLICATION */


MOV AX,0000H
MOV DS,AX
MOV AX,[1030H]
MOV BX,[1032H]
MUL BX
MOV [1034H],BX
INT

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

Program:- /* 8 BIT DIVISION */

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

Program: /* 16 BIT DIVISION */

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.

Conclusion: In this way we perform 8 bit and 16 bit division.

You might also like