Forum: Mikrocontroller und Digitale Elektronik 8051 How to set the PSW after an ADD/ADDC Instruction?


von th_reinb (Gast)


Lesenswert?

Hallo 8051 Cracks,

Meine Frage bezieht sich auf das Verhalten des 8051 nach einem ADD 
Befehl, im Besonderen interessiert mich wie die einzelnen Bits im PSW 
danach gesetzt werden:

Ein Beispiel:

Current Program Memory Content:
0x0a51 24 fa

Das ist folgende Instruction:
ADD A,#FA

Also der Konstante Wert 0xFa wird dem Accumulator hinzuaddiert.

Ausgangssituation:

Accumulator: 0x09
PSW: 0x00

Jetzt wir die Instruction ausgeführt:
ADD A,#FA

Addition in Binary:

 11111010    #data:
 00001001    Accumulator
________+
100000011    Result


So wenn man das nun mit Keil's C51 Simulator simuliert dann sieht das 
Ergebnis so aus:

PSW = 0xC0 = 11000000 => CY=1, AC=1, OV=0

Meiner Meinung nach sollte es aber so aussehen:
PSW = 0x84 = 10000100 => CY=1, AC=0, OV=1

aus dem Datasheet und 8052.com kann man entnehmen:

The Carry bit (C) is set if there is a carry-out of bit 7. In other 
words, if the unsigned summed value of the Accumulator, operand and (in 
the case of ADDC) the Carry flag exceeds 255 Carry is set. Otherwise, 
the Carry bit is cleared.

The Auxillary Carry (AC) bit is set if there is a carry-out of bit 3. In 
other words, if the unsigned summed value of the low nibble of the 
Accumulator, operand and (in the case of ADDC) the Carry flag exceeds 15 
the Auxillary Carry flag is set. Otherwise, the Auxillary Carry flag is 
cleared.

The Overflow (OV) bit is set if there is a carry-out of bit 6 or out of 
bit 7, but not both. In other words, if the addition of the Accumulator, 
operand and (in the case of ADDC) the Carry flag treated as signed 
values results in a value that is out of the range of a signed byte 
(-128 through +127) the Overflow flag is set. Otherwise, the Overflow 
flag is cleared.

Was sagen die 8051 Cracks dazu?
Warum setzt der Keil Simulator das PSW auf 0xC0?
Welche Auffassung ist den nun Richtig?

vielen Dank im Voraus

lg aus Wien,
Thomas

von Hagen R. (hagen)


Lesenswert?

876543210
 11111010    #data:
 00001001    Accumulator
________+
100000011    Result

Bit 3 ist 1 + 1 = 10, also AC muß 1 werden. Stell dir einfach vor das 
die Bits 3210 mit einem separatem Bit 4 davor expandiert wurden, und 
dieses virtuelle Bit 4 wäre das Carry einer 4 Bit breiten Operation.
Bits 4,5,6,7 sind alle 1 also propagiert sich dieses Carry bis ins Bit 
8, und Bit 8 ist einfach das Carry Flag in fast jeder CPU für 8 Bit 
breite Operationen, ergo CY = 1.
Da Bit 6 und Bit 7 ein Überlauf erzeugt haben, muß OV=0 sein. Das darf 
nur 1 werden wenn nur eines der beiden Bits einen Überlauf erzeugt hat. 
Bei Vorzeichenbehafteten Operationen zählt ja Bit 7 als "Vorzeichenbit".

Also meiner Meinung nach alles ok mit dem PSW.

Gruß Hagen

von th_reinb (Gast)


Lesenswert?

vielen Dank,

Jetzt hab ichs auch kapiert.

cheers,
Thomas

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.