You are on page 1of 5

CSE 2006 LAB ASSIGNMENT – 2

Mridul Jadon
20BCE1734

Aim: To find the average of an array and the sum of each element of two arrays.
Tool Used: Assembler - MASM 611

AVERAGE OF ARRAY
Algorithm: Execution of Code
1. Mount C drive using C:\directory_of_masm_folder
2. Give edit file_name.asm to start editing the code
3. Give masm file_name.asm to execute file
4. Give link file_name.obj to link executed file
5. Give debug file_name.exe to view output
6. Give ‘u’
7. Give ‘g’ followed by the address of HLT or INT to view the values in registers

Program Logic
1. An array (DW) with each member occupying 2 bytes is created
2. “DATA” is stored in DS using MOV command
3. CX is given the value 5H (the size of the array) and AX is given the value 0H
4. SI is assigned the beginning address of the array using LEA command
5. Within the loop the contents of SI is progressively added to AX, and CX is decremented by 1 with each
iteration
6. The loop ends using the JNZ command when CX reaches the value 0H
7. Outside the loop AX is divided by 5H which is moved into DL using DIV
Program

Sample Input
If array is 3H 5H 7H 4H 1H

Sample Output
Average is (3H+5H+7H+4H+1H)/5H = (14H)/5H = 4H

Register/ Memory Contents for I/O:


Snapshot of the Output:

Sum of each element of two Arrays


Algorithm:
Program Logic:
1. 2 DB arrays NUM1 and NUM2 are created with 4 elements each, a RESULT array is also created with 4
values of 0
2. “DATA” is moved into DS
3. SI is assigned the beginning address of NUM1, DI is assigned that of NUM2 and BX is assigned that of
RESULT using LEA
4. The contents of SI and DI is added and moved into the location represented by BX, via AL
5. Then BX, SI and DL are all incremented within the loop using the LOOP1 statement

Execution of Code:
1. Mount C drive using C:\directory_of_masm_folder
2. Give edit file_name.asm to start editing the code
3. Give masm file_name.asm to execute file
4. Give link file_name.obj to link executed file
5. Give debug file_name.exe to view output
6. Give ‘u’
7. Give ‘g’ followed by the address of HLT or INT to view the values in registers
8. To view the address in DS give the command ‘d’ followed by the address of DS with specification for
the number of bits you wish to view (indexed from 0000)
Program:

Sample Input
If NUM1= 8H 6H 2H 3H
NUM2= 7H 2H 7H 1H

Sample Output
RESULT= 15H 8H 9H 4H

Register/ Memory Contents for I/O:


Snapshot of the Output

Result: The average of all elements in the array has been found and the sum of all elements
in 2 arrays have also been successfully obtained

You might also like