1

So i need to filter out the positive numbers and display the sum if it is less than FFH, if not display FFH. i typed the code in the simulator and use #DB to store the numbers in a particular memory location. but when i run it step by step the memory content register is displaying 00. how to resolve it?

      MVI B,00
      MVI C,0A
      LXI H,4000

NEXT:      MOV A,M
      RAL
      JC REJECT
      RAR
      ADD B
      JC OVR
      MOV B,A

REJECT:    INX H
      DCR C
      JNZ NEXT
      STA 8070

OVR:       MVI A,FF
      HLT
# ORIGIN 4000H
# DB 28H, D8H, C2H, 21H, 24H, 30H, 2FH, 19H, F2H, 9FH

GNUSim8085

mahibonu10
  • 11
  • 4
  • 1
    You should specify which assembler you're using. – Michael Mar 01 '21 at 08:44
  • Adding any two negative numbers will always produce a carry-out. That's not the same thing as signed overflow. IIRC 8080 / 8085 doesn't have a flag for that, so it's rather inconvenient. But on any given addition, if adding two negatives produces a positive, that's signed overflow. – Peter Cordes Mar 01 '21 at 19:19
  • Also, `0xFF` is `-1`, the greatest/highest negative number (in 2's complement). So the instructions are telling you to display the sum unless the sum is 0xFF, then display FF. So you always have to display the exact sum, like with extended precision to handle a 2-byte sum? – Peter Cordes Mar 01 '21 at 19:20
  • Or are you supposed to only *keep* the positive numbers, not remove them, and treat the sum as unsigned? That makes overflow detection and handling much easier. – Peter Cordes Jun 25 '21 at 18:44

1 Answers1

0

What do you mean by 'memory content register'? If you are referring to M it is not an actual register, it denotes the contents at the memory location pointed by the HL register pair. At the end of your code HL will have 400AH and memory location 400AH can hold any garbage value.

Since you are using a simulator where memory cells are usually initialized to 0, your simulator shows contents of M is 0 which is perfectly normal. What you should look at is the contents of register A.

codeR
  • 165
  • 1
  • 1
  • 13