What does the half carry flag do?
It indicates when a carry or borrow has been generated out of the least significant four bits of the accumulator register following the execution of an arithmetic instruction. It is primarily used in decimal (BCD) arithmetic instructions.
What is the purpose of the carry bit?
In computer processors the carry flag (usually indicated as the C flag) is a single bit in a system status register/flag register used to indicate when an arithmetic carry or borrow has been generated out of the most significant arithmetic logic unit (ALU) bit position.
What is the difference between carry flag and overflow flag?
Carry Flag is a flag set when: a) two unsigned numbers were added and the result is larger than “capacity” of register where it is saved. Overflow Flag is used as CF but when we work on signed numbers. Ex we wanna add two 8 bit signed numbers: 127 + 2.
How do you get a carrying flag?
Carry Flag
- The carry flag is set if the addition of two numbers causes a carry out of the most significant (leftmost) bits added. 1111 + 0001 = 0000 (carry flag is turned on)
- The carry (borrow) flag is also set if the subtraction of two numbers requires a borrow into the most significant (leftmost) bits subtracted.
What is binary coded decimal number?
Binary coded decimal (BCD) is a system of writing numerals that assigns a four-digit binary code to each digit 0 through 9 in a decimal (base-10) numeral. The four-bit BCD code for any particular single base-10 digit is its representation in binary notation, as follows: 0 = 0000. 1 = 0001. 2 = 0010.
Which is the carry out flag on Z80?
So overflow flag = carry-out flag XOR carry from bit 6 into bit 7. Both my and your ways of calculating the overflow flag are correct. In fact, both are described in the Z80 CPU User’s Manual in section “Z80 Status Indicator Flags”.
What makes a Game Boy Z80 half carry?
To put things in perspective, the z80 has a 4bit ALU and performs 8bit ops by doing two 4bit ops. So it gets half carry very naturally, as an intermediate result.
How did the Z80 do 16 bit arithmetic?
So if the Z80 gets an instruction like ADD HL, BC, the microprogram probably goes something like this: The result is a 16-bit addition, just that it’s done four bits at a time. Some Z80 compatibles had microcode that did what I describe, but microcode is not the only way to achieve this.
How big is the ALU on the Z80?
In the case of the Z80, the ALU is only 4 bits wide. That’s no problem, since the internals of the CPU are controlled by a program internal to the processor, called the microprogram (or microcode), which is responsible for piping data around in the necessary way to execute some instruction.