30 ms·
On the assembly language level, you have compare instructions. These subtract, and throw away the result, but leave the flags. Many CPUs have a flag that is a
by tenebrisalietum 7y ago
On the assembly language level, you have compare instructions. These subtract, and throw away the result, but leave the flags.
Many CPUs have a flag that is automatically raised if a value is 0.
This means you don't have to execute a compare instruction to test if a value is 0, because the "Zero" flag will be set as soon as the 0 value is loaded.
That means you can load a value, and directly go to a BEQ (which is really shorthand for "if zero flag = 0") and save a few cycles by avoiding the CMP instruction.
So this is why numbering starts at zero. Testing if your list is empty, which is probably a common thing if you loop through each element, is slightly quicker.