23DCS056_Parc7
23DCS056_Parc7
23DCS056_Parc7
Date: 18/09/2024
EXPERIMENT NO. 7
AIM: Create an array. Perform addition of all even numbers from array and save answer in
one variable.
ALGORITHM:
Step:1 Set Data Segment:
Load the value 2000h into the AX register.
Set the DS register to AX, initializing the data segment to 2000h.
Step:2 Initialize Index and Counter:
Set SI to 50h, pointing to the starting address of the array in memory (DS:50h).
Set CL to 5h, initializing the loop counter to 5, which represents the number of in the array.
Step:3 Initialize Sum:
Set AL to 0, initializing the accumulator to store the sum of even numbers.
Step:4 Loop through the Array:
Repeat the following steps 5 times (controlled by CL).
Step:5 Inside the Loop:
Load the byte at the address [SI] (the current element in the array) into BL.
Use the test bl, 01h instruction to check if the least significant bit (LSB) is 0(indicating an even
number).
If the number is odd (LSB is 1), skip the addition step by jumping to L1.
If the number is even, add it to the accumulator (AL) using add al, bl.
Increment SI to point to the next element in the array.
Use the loop instruction to decrease CL and repeat the loop until CL becomes 0.
Step:6 End the Program:
When all 5 elements have been processed, return control to the caller using the ret instruction.
CODE:
org 100h
mov ax, 2000h
mov ds, ax
mov si, 50h
mov cl, 5h
mov al, 0h
l2:
mov bl, [si]
test bl, 01h
jnz l1
add al, bl
l1:
inc si
loop l2
ret
ID :23DCS056
CSE-DEPSTAR CSE202-Microprocessor and Computer Organization
STEP-BY-STEP EXECUTION:
{Remove this comment before printing: edit following section as per requirement}
ID :23DCS056
CSE-DEPSTAR CSE202-Microprocessor and Computer Organization
CONCLUSION:
The given assembly code sums all the even numbers from a memory array of 5 elements. It checks
each number using a bitwise test to determine if it's even, and adds even values to the ‘AL’ register.
The loop iterates over each element in the array, and the sum of all even numbers is stored in the ‘AL’
register when the program completes. This demonstrates basic use of looping, conditional checks, and
arithmetic in 8086 assembly language.
ID :23DCS056