Did bit one of the Intel 8080's Flags register, the bit between the carry and parity flags, get set to one on startup? If so what was the reason for this, and was this inherited from the 8008 Flags register?
3 Answers
Did bit one of the Intel 8080's Flags register, the bit between the carry and parity flags, get set to one on startup?
TL;DR:
No, as there is no flag register on the 8080. Only separate flags. The 'filler' bits (1, 3, 5) only get their values when PUSH PSW
is executed.
Long Read:
The 8080 does not have a flag register, but like its predecessor the 8008, separate flags. Which are, like other answers correctly describe, in random states after power-up/reset.
The 8080 flags have no access in register form for the programmer. Only testing in conditioned instructions is possible. Setting could only be done via instructions with implied result stored in any of them. The only access as byte data was when pushed onto the stack.
When storing the flags to the stack (PUSH PSW
) the second byte is synthesized from the flag bits and completed by 'filler' values for positions 1, 3, 5 (1, 0, 0). This guarantees that in memory bit 1 always will be 1.
(From "8080 Assembly Language Programming Manual", "Rev B", p.22/23)
During store (PUSH PSW
)
If register pair PSW is specified, the first byte of information
saved holds the contents of the A register; the
second byte holds the settings of the five condition bits,
i.e., Carry, Zero, Sign, Parity, and Auxiliary Carry. The format
of this byte is:
| | | |A| | | | |
|S|Z|0|C|0|P|1|C|
S State of Sign bit
Z State of Zero bit
0 always 0
AC State of auxiliary Carry bit
0 always 0
P State of Parity bit
1 always 1
C State of Carry bit
For retrieval (POP PSW
):
[...] If register pair
PSW is specified, the byte of data indicated by the contents
of the stack pointer plus one is used to restore the values of
the five condition bits (Carry, Zero, Sign, Parity, and Auxiliary
Carry) using the format described in the last section.
If so what was the reason for this, and was this inherited from the 8008 Flags register?
In part, as they were separate single-bit entities. Except the 8008 did not allow any access to the flags beside testing them in conditional instructions. There was no instruction to store or retrieve them at all.
Tidbits on x80-Family Flags:
The grand daddy of all things 80, the Datapoint 2200 laid the ground here by defining them as separate flip-flops, only accessible using conditional instructions. They are not presented as a register-like structure in any way.
The 8008, being a single chip implementation of the 2200, followed that, while the 8080 did introduce a register-like view for its programming model, but not in hardware.
Only the follow up 8085 did introduce a real flag register (*1), still not in the register file, but kept separate, like the A register (*2). Now bit 1 was used as V flag. That's one of the incompatibilities with 8080 code - and one way to detect a 8085: by pushing a cleared HL, popping PSW, pushing PSW again and then checking L. If bit 1 is still cleared, it's an 8085.
The Z80, in contrast, added a flag register (or more accurately two, as there's one in the alternate register set too) as part of its huge register file, but workings were still based on separate flip-flops located near the ALU. At the beginning of every instruction the content of the flag register in use got copied into the flag flip-flops, and copied back at the end. This process is a must when handling two separate register sets and also keeping the flags close to the ALU.
The Datapoint 2200 Version 2 also had two register sets: no flag register, but two sets of flag flip-flops multiplexed toward the ALU (like the registers).
*1 - Well, almost, as only 7 storage bits are implemented. Bit 3 was replaced by a circuit to always drive 0 when read.
*2 - On the 8008 and 8080, the A register was also not a member of the register file.
-
2I voted +1 as this all sounds correct; who voted -1? "It's not set at startup because it doesn't exist" sounds like a good contribution to me.– TommySep 12, 2019 at 17:43
-
1@SingleMalt Well, for a definitive Answer one may have to go thru the circuitry. It may as well be due the way the data lines are layouted. Ken Shirriff might be a good source to ask here. The 8086 flag register was on purpose made to work similar to the 8080 to ease automatic program conversion.– RaffzahnSep 12, 2019 at 20:23
-
1@Raffzahn definitely seems plausible to do with the circuitry. Appreciate the additional information that 8085 was the first of these to introduce a real register flag, and the link about its V flag. Sep 12, 2019 at 20:49
-
1So, this seems to be a Heisenberg thing: Once you start looking at it (PUSH PSW), it suddenly is different ;)– tofroSep 12, 2019 at 22:23
-
2@TripeHound I guess it could have been made. But then again, there was no particular need for a specific sequence or assignment - the 8008 had no way to access them. Looking at the die shot - the flag FF are at the lower edge of what's marked as ALU - it may be simply related to routing - rather tight in that area :)– RaffzahnSep 13, 2019 at 10:28
According to the manual, the only thing that is explicitly set after RESET in the 8080 is the program counter. Everything else is indeterminate:
Note, however,that the RESET has no effect on status flags, or on any of the processor's working registers (accumulator, registers, or stackpointer). The contents of these registers remain indeterminate, until initialized explicitly by the program.
If they don't initialize anything at all, it is very unlikely they'd initialize something that isn't even used.
-
2I like the 'unlikely' part :)) Except, for all ever visible to programmers, they will look like initialized. Cool, isn't it?– RaffzahnSep 12, 2019 at 18:14
According to the Intel 8080 microcomputer systems user’s manual, the contents of registers are indeterminate on startup:
The contents of its program counter, stack pointer, and the other working registers are naturally subject to random factors and cannot be specified.
And further on:
Note, however, that the
RESET
has no effect on status flags, or on any of the processor's working registers (accumulator, registers, or stack pointer). The contents of these registers remain indeterminate, until initialized explicitly by the program.
-
2