Post subject: GBC Instruction A7 - AND A (Disassembling)
gia
Player (109)
Joined: 5/3/2006
Posts: 223
Hi, first I am not experienced at all on this but I was disassembling with bgb and noticed the instruction AND A, which sounds a bit pointless because the docs say it does A = A&A... unless its just for setting the Z flag... whatever. Anyway, after executing it, the A register was untouched, thats ok, but the F register changed and I can't tell exactly what operation it was supposed to do. Same thing happens with XOR A btw. //AF = 0140 AND A //AF = 0120 XOR A //AF = 0180 (...) //AF = 0080 AND A //AF = 00A0 (...) //AF = 0070 AND A //AF = 00A0 wtf Then I googled and found several game boy technical faqs, and all of them say that A7 means AND A, then googled for Z80 opcodes and they also say the same thing and add that its supposed to do A=A&A. So could someone explain how it is supposed to work or if it is a bug on the emulator please? Also, whats the cnt register, does it get reduced by the time in clocks the instruction was supposed to take?
Active player (286)
Joined: 3/4/2006
Posts: 341
The OR, AND, and XOR commands all clear the carry flag and clear/set the zero flag depending on whether the result is 0. OR A (or AND A) is faster and uses fewer bytes than CP 0, so it's the preferred way to determine whether the accumulator is equal to zero. The F register contains all of the flags, so that's why it changed when the AND A command was executed.
gia
Player (109)
Joined: 5/3/2006
Posts: 223
Oh, lol ty