23DCS056_Parc7

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

CSE-DEPSTAR CSE202-Microprocessor and Computer Organization

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}

Instruction Screenshot Value in Operation (Before execution of (After execution of


in of the Instructio executed by instruction) Content of instruction)
Assembly Instruction n Pointer instruction to be affected Content of
Language in program Registers/Memory affected
memory locations and flags Registers/Memory
locations and flags
mov ax,2000h mov ax,2000h
loads the value in
ax
mov ds,ax Mov da,ax loads the
value from ax,ds

mov si,50h Mov si,50h set the si


to 50h

mov cl,5h Mov cl,5h set the cl


to the 5h

mov al,0h Mov al,0h set the al


to the 0h

mov bl,[si] Mov bl,[si] set the


bl to the si
test bl,01h The instruction `test
bl, 01h` checks if
the least significant
bit of the `BL`
register is 1 or 0.
jnz l1 The instruction
`JNZ L1` means
"Jump to the label
`L1` if the result of
the previous
operation is not zero
add al,bl Add al,bl means that
al + bl
inc si Increase Si by 1

loop l2 LOOP traversal for


the cl times here 5
inc si 2nd traversal of the
loop
add a1.b1 Add al,bl means that
al + bl
inc si 3rd traversal of the
loop

inc si 4th traversal of the


loop

inc si 5th traversal of the


loop

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy