0% found this document useful (0 votes)
29 views5 pages

EXP1

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

EXP1

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

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 storage locations in memory.
Mnemonic Meaning Format Operation Flags affected
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:-

Rules for Addition (8 bit and 16 bit addition)

A(i/p) B(i/p) Y(o/p) Carry(o/p)


0 0 0 -
0 1 1 -
1 0 1 -
1 1 0 1
Result: -
[1030H]=05
[1032H]=05
[1034H]=0A.

Program:- /* 16 BIT ADDITION */

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

Observations:-

Result: -
[1030H]=1000
[1032H]=2021
[1034H]=3021

Conclusion:

The internal registers along with FLAG register is understood and 8-bit and 16-bit addition is
implemented.

You might also like