Write an ALP of 8086 to add series of N 16 bit numbers.
Program statement : Write an ALP to add a block of N numbers. Assume result to be 16 bit.
Explanation :
- Consider that a block of N bytes is present at source location.
- Let the number of bytes N = 10 for example.
- We have to add these N bytes.
- We will initialize this as count in the CX register.
- We know that source address is in the SI register. This SI register will act as pointer.
- Clear the direction flag.
- Using ADD instruction add the contents, byte by byte of the block.
- Increment SI to point to next element.
- Decrements the counter and add the contents till all the contents are added.
- Result is stored in AX.
Flow chart
Algorithm :
Step I : Initialize the data segment.
Step II : Initialize SI as pointer with source address.
Step III : Initialize CX register with count.
Step iv : Initialize direction flag to zero.
Step v : Add data, word by word.
Step vi : Increment pointer i.e. SI by 2 as 16 bit addtion.
Step vii : Decrement counter CX.
Step viii : Check for count in CX, if not zero goto step v else goto step ix.
Step ix : Store the result of addition.
Step x : Stop.
Porgram :
Result
: AX = 39FCH
Step I : Initialize the data segment.
Step II : Initialize SI as pointer with source address.
Step III : Initialize CX register with count.
Step iv : Initialize direction flag to zero.
Step v : Add data, word by word.
Step vi : Increment pointer i.e. SI by 2 as 16 bit addtion.
Step vii : Decrement counter CX.
Step viii : Check for count in CX, if not zero goto step v else goto step ix.
Step ix : Store the result of addition.
Step x : Stop.
Porgram :
Lable
|
Instruction
|
Comment
|
I.
|
.model small
|
|
.data
|
||
Series db 0111H, 0231H, 0341H, 0456H,
0578H
|
||
06ABH, 0733H, 0845H, 0976, OA12H
|
||
Count dw OAH
|
||
.code
|
||
mov ax, @data
|
Initialize data segment
|
|
mov ds, ax
|
||
mov ax, 0
|
||
mov si, offset blk 1
|
Initialize pointer
|
|
mov cx, count
|
Initialize counter
|
|
cld
|
Df = o
|
|
II:
|
add ax, [si]
|
Add numbers
|
inc si
|
Increment pointer
|
|
inc si
|
Increment pointer
|
|
dec count
|
Decrement counter
|
|
jnz 11
|
Check if all no. are added
|
|
end
|
Post a Comment