8051 How to set the PSW after an ADD/ADDC Instruction?

Gast #718485
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
#718498
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

Antwort schreiben

Eine eigene Frage? Dieser Thread ist über 18 Jahre alt. Stell sie in einem eigenen Thread – dort lesen mehr Leute mit, und sie wird öfter und schneller beantwortet.

Neuen Thread starten

Eine Lösung, Ergänzung oder Rückmeldung zu diesem Thread? Dann antworte hier.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.