Search code examples
8085cpu-architecture

8085 program to add two 8-bit numbers in 8085 simulator


I am trying to add two 8 bit number and wrote the following code:

MVI D 08h
MVI B 03h
MVI C 00h
MOV A D
LOOP: CMP B
JC DOWN
INR A
SUB B
JNZ LOOP

DOWN: HLT

But I got incorrect output.


Solution

  • Well assuming my assumption is correct that you are storing answer in C,

    then just do a small change on 7th line:

    MVI D 08h
    MVI B 03h
    MVI C 00h
    MOV A D
    LOOP: CMP B
    JC DOWN
    INR C
    SUB B
    JNZ LOOP
    
    DOWN: HLT
    

    It should work now.