You are on page 1of 7

Experiment No 2

Sum of numbers in a series

4304 4303 4302 4301 4300

4306 4305
• Move 00 to register B immediately for carry
• Load the data of memory [4300] into H immediately
• Move value of memory into register C
• Decrease C by 1
• Increase H-L pair by 1
• Move value of memory into accumulator
• Increase H-L pair by 1
• Add value of memory with accumulator
• Jump if no carry to step 11
• Increase value of register B by one
• Decrease register C by 1
• Jump if not zero to step-7
• Store content of accumulator into memory [4305] (result)
• Move content of register B into accumulator
• Store content of accumulator into memory [4306] (carry)
• Stop
Sorting of numbers
• Load size of list in C register and set D register to be 0
• Decrement C as for n elements n-1 comparisons occur
• Load the starting element of the list in Accumulator
• Compare Accumulator and next element
• If accumulator is less than next element jump to step 8
• Swap the two elements
• Set D register to 1
• Decrement C
• If C>0 take next element in Accumulator and go to point 4
• If D=0, this means in the iteration, no exchange takes place consequently
we know that it won’t take place in further iterations so the loop in exited
and program is stopped
• Jump to step 1 for further iterations
Searching a number in an array
• Make the memory pointer points to memory location 2050 by help of LXI H 2050
instruction
• Store value of array size in register C
• Store number to be search in register B
• Increment memory pointer by 1 so that it points to next array index
• Store element of array in accumulator A and compare it with value of B
• If both are same i.e. if ZF = 1 then store F0 in A and store the result in memory
location 3051 and go to step 9
• Otherwise store 0F in A and store it in memory location 3051
• Decrement C by 01 and check if C is not equal to zero i.e. ZF = 0, if true go to step
3 otherwise go to step 9
• End of program

You might also like