Thursday, December 15, 2022

WAP to add 10 data bytes stored in memory locations starting at 2500H onwards and display the sum at memory location 2100H if the sum does not generate a carry. If a result generates a carry, stop the addition and store 01H at memory location 2100H.

Here is a simple program in 8085 assembly language that adds 10 data bytes stored in memory locations starting at 2500H onwards and displays the sum at memory location 2100H if the sum does not generate a carry. If a result generates a carry, the program stops the addition and stores 01H at memory location 2100H:


MVI A, 00H ; Initialize the accumulator to 0

MVI B, 00H ; Initialize the counter to 0


LOOP:

ADD M ; Add the value at the memory location pointed to by the HL register pair to the accumulator

INR B ; Increment the counter

JNC NEXT ; If no carry is generated, go to the next iteration

MVI A, 01H ; Store 01H in the accumulator to indicate that a carry was generated

STA 2100H ; Store the value in the accumulator at memory location 2100H

HALT ; Halt the program


NEXT:

INX HL ; Increment the value in the HL register pair to point to the next memory location

CMP B, 10 ; Check if the counter has reached 10

JNZ LOOP ; If the counter has not reached 10, go to the next iteration of the loop

STA 2100H ; If the counter has reached 10, store the value in the accumulator at memory location 2100H

HALT ; Halt the program

 

This program first initializes the accumulator and the counter to 0. It then enters a loop that adds the value at the memory location pointed to by the HL register pair to the accumulator. It then increments the counter and checks if a carry was generated by the addition. If a carry was generated, the program stores 01H at memory location 2100H and halts. If no carry was generated, the program increments the HL register pair to point to the next memory location, checks if the counter has reached 10, and repeats the loop if necessary. If the counter has reached 10, the program stores the final value in the accumulator at memory location 2100H and halts.



No comments:

Software scope

 In software engineering, the software scope refers to the boundaries and limitations of a software project. It defines what the software wi...