3 ms·
> is the very efficient use of registers It's of course more than that: just reading the start, one can see that the author placed the variables immediately af
by acqq 7y ago
> is the very efficient use of registers
It's of course more than that: just reading the start, one can see that the author placed the variables immediately after the bytes of the screen, and the screen starts on the position 0. So at the start he clears both the screen and his variables up to the variables "level" and "lives" with:
xor ax,ax
mov cx,level/2 ; Clear screen and variables (except level/lives)
xor di,di
rep
stosw
(Note here that the whole rep stosw loop is 2 bytes only. That's the feature of the 8086 instruction set. The memory was expensive then.)
At that moment he will load both the level and the lives variables with just:
mov ax,[di]
and then increase the level by 2 and store it back
inc ax
inc ax
stosw
The last three instructions are encoded with just 3 bytes:
40 inc ax
40 inc ax
AB stosw
Etc. it's more than just allocating registers, it's having the overview of what one wants and how it can organize the whole to minimize the number of instructions for all tasks together. And, of course, using the instruction set that was designed to save the memory for code.
Specifically, in C, as an example, the compiler still expects that it's the programmer who plans the memory layout, it can't reorganize where you place what for you.