8086 program to find sum of odd numbers in a given series - GeeksforGeeks

01 Jun, 2021
Problem – Write an Assembly Language Program to find sum of odd numbers in a given series containing 8 bit numbers stored in a continuous memory location and store the result in another memory location. 
Example – 
 
Example Explanation – 
500 offset stores the counter value of the series and the elements of the series starts from 501 to 504 offset. In this example, we have 4 terms only. Adding the odd terms (found in BL register) 15+07 in AL register and result gets stored (1C) in AL register. The result from AL register gets stored in 600 offset.  
500 offset stores the counter value of the series and the elements of the series starts from 501 to 504 offset. 
In this example, we have 4 terms only. Adding the odd terms (found in BL register) 15+07 in AL register and result gets stored (1C) in AL register. 
The result from AL register gets stored in 600 offset.  
Assumptions – 
The counter value which tells that how many numbers are there in the series is stored at memory location 500. The elements of the series are stored in a continuous memory location starting from 501. The result is stored at a memory location 600. The starting address of the program is 400.  
The counter value which tells that how many numbers are there in the series is stored at memory location 500. 
The elements of the series are stored in a continuous memory location starting from 501. 
The result is stored at a memory location 600. 
The starting address of the program is 400.  
Test – 
Syntax: TEST d, s 
It performs AND operation of destination(d) and source(s) but result is not stored only flags ate modified. 
Algorithm – 
Load data from offset 500 to register CL. Increment the value of offset. Load 00H into CH register. Load 00H into AL register. Load data from offset to register BL. Use TEST instruction to check whether data in BL is even or odd, if zero flag is set means data is even then go to step 7 otherwise data is odd then go to step 8. Jump to memory location 413H. Add the data of AL and BL registers and store the result in AL register. Increment the value of offset. Jump to memory location 40AH if content of CX is not equal to zero otherwise go to step 11. Load the data from AL register to memory location 600. End  
Load data from offset 500 to register CL. 
Increment the value of offset. 
Load 00H into CH register. 
Load 00H into AL register. 
Load data from offset to register BL. 
Use TEST instruction to check whether data in BL is even or odd, if zero flag is set means data is even then go to step 7 otherwise data is odd then go to step 8. 
Jump to memory location 413H. 
Add the data of AL and BL registers and store the result in AL register. 
Increment the value of offset. 
Jump to memory location 40AH if content of CX is not equal to zero otherwise go to step 11. 
Load the data from AL register to memory location 600. 
End  
Program – 
 
Explanation – 
MOV SI, 500 load the value 500 to SI. MOV CL, [SI] loads the data of offset SI into CL register. INC SI increases the value of SI by one. MOV CH, 00 loads the value 00 into CH register. MOV AL, 00 loads the value 00 into AL register. MOV BL, [SI] loads the data of offset SI into BL register. TEST BL, 01 AND operation of content of BL and value 01 and flag registers are modified. JZ 413 jump to 413 memory location if zero flag is set. ADD AL, BL add the contents of AL and BL registers and store the result in AL register. INC SI increases the value of SI by one. LOOP 40A jump to 40A memory location if value of CX is not equal to zero. MOV [600], AL loads the content of AL register to memory location 600. HLT stops the execution of the program. 
MOV SI, 500 load the value 500 to SI. 
MOV CL, [SI] loads the data of offset SI into CL register. 
INC SI increases the value of SI by one. 
MOV CH, 00 loads the value 00 into CH register. 
MOV AL, 00 loads the value 00 into AL register. 
MOV BL, [SI] loads the data of offset SI into BL register. 
TEST BL, 01 AND operation of content of BL and value 01 and flag registers are modified. 
JZ 413 jump to 413 memory location if zero flag is set. 
ADD AL, BL add the contents of AL and BL registers and store the result in AL register. 
INC SI increases the value of SI by one. 
LOOP 40A jump to 40A memory location if value of CX is not equal to zero. 
MOV [600], AL loads the content of AL register to memory location 600. 
HLT stops the execution of the program. 
Akanksha_Rai
shekharsaxena316
microprocessor
system-programming
Computer Organization & Architecture
microprocessor
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Architecture of 8086
Logical and Physical Address in Operating System
Computer Organization and Architecture | Pipelining | Set 1 (Execution, Stages and Throughput)
Addressing modes in 8085 microprocessor
Computer Organization | RISC and CISC
Architecture of 8085 microprocessor
Interrupts
Memory Hierarchy Design and its Characteristics
IEEE Standard 754 Floating Point Numbers
Computer Organization | Instruction Formats (Zero, One, Two and Three Address Instruction)