Saroupille wrote
Hi,
I'm wondering how can divde a number by 2 ? I need of this operation to clean the screen. Indeed if in some address the number 0000000000000011 is stored, then I need to have the number 0000000000000001.
I thought to store all the different numbers possible (1,3,7,15,31, etc...) but i need a counter to select the good register. So what is the simplest way to do this ?
Thanks.
Division is a hard problem on the Hack processor. As part of chapter 12 you will write an integer division function.
For the Fill.asm program, try to think of an algorithm that does not need division. Hint: you don't need to write to each pixel individually; write them 16 pixels at a time.
If you truly need division by 2, and your input values are limited to small values, the easiest way would be an algorithm something like:
// compute y = x/2, unsigned
x = 0
y = y AND NOT 1 // clears bit 0
while (x < y) {
x = x + 1
y = y - 2
}
--Mark