I would like to do bit-rotation in HACK assembly (nand2tetris). For example:
11110000 becomes: 11100001
How will I do this? I saw that normal assembly has the rol syntax that does that but I cant find one for HACK assembly
I would like to do bit-rotation in HACK assembly (nand2tetris). For example:
11110000 becomes: 11100001
How will I do this? I saw that normal assembly has the rol syntax that does that but I cant find one for HACK assembly
This answer is going to be somewhat Socratic in nature as the point of Nand2Tetris is to learn things, and you'll learn much more if you figure this out yourself.
There is no ROL instruction in HACK, so you have to build it from what you have available. Here are some questions to ask yourself:
If you need to do a ROL on less than a full word (16-bit) value, I suggest you solve the problem for full words, then adapt it to handle the bit length you need.
First check the msb. Nand2Tetris use 2's complement
if a < 0, msb = 1, else (a >= 0) msb = 0
Keep the msb 0 or 1
And, left shift means multiply by 2, a * 2 -> D = D + D or D = D + M Discard overfloww
finally, add keeping msb value...