Hacker News new | ask | show | jobs
by earthbee 1758 days ago
What significant advantage does that have over a conditional branch followed by an RTS?
1 comments

Code density, and you could potentially save a few cycles with a single instruction. Whether that matters at all depends on how much slack you have in your utilization of available memory and CPU cycles. (Strictly talking about "old" CPUs here.)

It's worth noting that the 8086 got rid of conditional returns, you only have unconditional ones there.

A taken branch on the 6502 takes 3 cycles. A not taken branch followed by a Return From Subroutine instruction takes 2 + 6 cycles.

Looking up the conditional return instructions on the 8080 seems to show it takes 5 cycles when false and 11 when true.

So the two 6502 instructions add up to being two or three cycles faster than one 8080 conditional return.

Cycle counts are super misleading. These processors were limited by the speed of RAM, and cycles per RAM access differed. Suppose you have RAM running at 1 MHz... maybe your 6502 is also clocked at 1 MHz, and your 8080 is clocked at 4 MHz. I know you're not trying to compare 6502 performance to 8080 performance in general, just that there's a fairly wide variation in how much you can accomplish in a cycle, and "how many RAM accesses can the processor make" is probably what you want to look for, since it's a bit more directly comparable across processors of that era.
I was not trying to compare the 6502 with the 8080 here, and I said "potentially" exactly because it depends on the architecture wether it works out (and, as said, 8088/8086 removed the conditional returns). On the 8080 specifically, conditional returns seem to be a little cheaper overall.
It’s only fair to compare cycle numbers if you also compare cycle times.