sim8085 icon indicating copy to clipboard operation
sim8085 copied to clipboard

Carry flag not set with POP PSW

Open bryc opened this issue 4 years ago • 0 comments

Consider the following code:

jmp main

main: nop
      mvi d, 0     ; use d for sum
      lxi b, data  ; data pointer location
      jmp loop
    
loop: ldax b       ; load byte at bc
      push psw     ; save registers before cpi clears them
      cpi 0        ; compare to 0 to break loop
      jz done
      pop psw      ; restore registers
      adc d
      mov d, a
      inr c        ; increase index for data bytes
      jmp loop
done: pop psw
      hlt

data: db 7Ah, 1Ch, 5Bh, 27h, D8h, 0h

There are two errors in the execution of this code.

First of all, lxi b, data does not work. Hardcoding the location to the data is a workaround.

Second of all, pop psw does not successfully set the carry flag when it should, causing the final result of d to be F0h when it should be F1h. The 1 is added due to the carry flag on the 4th loop.

Hope you can eventually improve sim8085, otherwise gnusim8085 is the only reliable alternative.

bryc avatar Jun 29 '21 00:06 bryc