Domanda

La CPU Game Boy Z80 ha una bandiera a metà carry e non riesco a trovare molte informazioni su quando impostare/cancellarla.

Quello che ho capito finora è che qualsiasi aggiunta, sottrai, spostamento o rotazione a 8 bit (e forse altri?) Imposta su Bit 4 del risultato (?) E le istruzioni DAA set/usano in qualche modo. Quello che non sono sicuro è come le istruzioni a 16 bit lo influenzano e se sono interessate o meno dall'uso di determinati registri.

È stato utile?

Soluzione

È il carry da bit 3 a bit 4, proprio come i normali record di bandiera carry da bit 7. Quindi, ad esempio per ottenere la metà di carry bit in un add:

((a&0xf) + (value&0xf))&0x10

Che fornisce 0x10 se si deve impostare mezzo trasporto, 0 altrimenti. Ottenere mezzo trasporto dalle altre operazioni pertinenti segue naturalmente: le domande sono se ci fosse il trasporto dal basso al massimo.

Per mettere le cose in prospettiva, lo Z80 ha un Alu a 4 bit ed esegue OP a 8 bit facendo due OP a 4 bit. Quindi ottiene metà trasporto in modo molto naturale, come risultato intermedio.

DAA è interessato alla bandiera perché se è impostata metà trasporto, sono state aggiunte due cifre che si sommano a più di 16 sono state aggiunte nel bocconcino basso; Ciò avrà prodotto correttamente il trasporto nel morso superiore ma avrà lasciato il bordo basso 6 inferiore a quello che dovrebbe essere, poiché c'erano altri sei valori tra 10, quando avrebbe dovuto generare trasporto e 16, quando lo ha fatto.

Altri suggerimenti

Per le operazioni a 16 bit, il carry da bit 3 a bit 4 nel byte alto del registro imposta il flag. In altre parole, bit 11 a bit 12.

(Nota che i bit sopra sono etichettati 0-15, dal minimo a più significativo)

Vedere qui: http://www.z80.info/z80code.htm

16 bit arithmetic

If  you want to add numbers that are more than the 0-255 that can
be stored in the A register,  then the HL, IX or IY registers can
be used. Thus LD HL,1000H:LD BC,2000H:ADD HL,BC will give

A  CZPSNH  BC   DE   HL   IX   IY  A' CZPSNH' BC'  DE'  HL'  SP
00 000000 2000 0000 3000 0000 0000 00 000000 0000 0000 0000 0000

The flags are set as follows.

C or carry flag          1 if answer >65535 else 0
Z or zero flag           not changed
P flag                   not changed
S or sign flag           not changed
N flag                   0
H or half carry flag     1 if carry from bit 11 to bit 12 else 0
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top