Sunteți pe pagina 1din 3

Middle Technical University Digital Controller Lab.

Electrical Engineering Technical College Third Stage


Electrical Power Technical Engineering Dept. Mohammed D. Altamemi

Experiment - 4
Add two (8-bit, and 16-bit) Numbers Using 8086 Microprocessor
4-1 Object:
Write a program to add two 8 bit numbers, and write a program to add two 16 bit
numbers using emu8086.
4-2 theory:
ADD des, src
ADC des, src
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.
Examples:
 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).
 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
00H or 0000H with no carry.
Example:
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].
Middle Technical University Digital Controller Lab.
Electrical Engineering Technical College Third Stage
Electrical Power Technical Engineering Dept. Mohammed D. Altamemi

INC TEMP [Increment byte or word named TEMP in the data segment].
Increment byte if TEMP declared with DB.
Increment word if TEMP is declared with DW.
INC PRICES [BX] [Increment element pointed to by [BX] in array PRICES].
Increment a word if PRICES is declared as an array of words;
Increment a byte if PRICES is declared as an array of bytes.
4-3 procedures:
Part I: add two 8-bit numbers

1. Start the program by loading the first data into Accumulator (AL)
2. Get the second data and load into (BL).
3. Add the two register contents (AL + BL).
4. Check for carry flag.
5. Store the value of sum and carry in memory location.
6. Terminate the program.
MOV CL, 00h ; Initialize CL register to 00
MOV AL, 41h ; Load the value to AL.
MOV BL, 51 ; Load the value to BL.
ADD AL, BL ; Add the value of register BL to A.
JNC LOOP ; Jump on no carry.
INC CL ; Increment value of register Cl
LOOP: MOV [1000h], Al ; Store AL to memory address (1000h).
MOV [1001h], CL ; Store the value of AL (CARRY)
HLT ; Halt the program.
[1000h] =? [1001] =?
Part II: add two 16-bit numbers

1. Start the program by loading the first data into Accumulator (AL)
2. Get the second data and load into (BL).
3. Add the two register contents (AL + BL).
4. Check for carry flag.
5. Store the value of sum and carry in memory location.
6. Terminate the program.
MOV AX, 1080H ; move 16-bit immediately to AX
Middle Technical University Digital Controller Lab.
Electrical Engineering Technical College Third Stage
Electrical Power Technical Engineering Dept. Mohammed D. Altamemi

MOV BX, 1FD0H ; move 16-bit immediately to BX


MOV CL, 00H ; move 00h to cl
ADD AX, BX ; add AX = AX+BX
JNC LOOP ; jump if no carry
INC CL ; increment CL by 1
LOOP: MOV [0105H], AX ; copy ax to [0105] and [0106].
MOV [0107H], CL ; copy CL to mem. [0107]
HLT ; halt the program
[0105h] =? [0106h] =? [0107h] =?
4-4 Discussion:
1. Write a program execute the following additions, test CF, and then storage the results and
CF in memory location.
A. 30h + 15h
B. C3A0h + 10FDh
C. 7Fh + 1234h
2. For A, B and C in step one each time after pressing the “single step” button, check
and record down the contents of AX and BX registers in Table 1
Table (1)

3. For A, B, and C in step one, use a calculator, calculate the answer for the above
arithmetic operations ………………………, Is it the same as the final answer in
the AX register? ……………………… .
4. Please express what you learn with this laboratory work with at most one paragraph.

S-ar putea să vă placă și