2
You can find the Hack Assembly Language specification here: http://www.cs.huji.ac.il/course/2002/nand2tet/docs/ch_4_machine_language.pdf
You can download the Hack Computer emulator here: http://www.nand2tetris.org/software.php
The goal is to write something similar to this:
int i = 1;
while(i<100){
i = i+i;
}
My solution is here:
@17 // Set Register A to 17
M = 1 // Set M[17] = 1
@17 // Set Register A to 17 --> This is location 2 btw
D = M // Set Register D to value stored in M[17]
A = D // Copy the value found in Register D to A
D = D+A // Set value in D = D + A
@17 // Set Register A to 17
M = D // Store the value in M[17] to the value of Register D
@100 // Store value 100 in Register A
D = D-A // Set value in D to D - 100
@2 // Set Register A to 2
D;JLT // If D<0 D is still not greater than 100. Goto location 2
Can you come up with something shorter?
2I'm not sure how to understand your question. This site is mainly for programming competitions. Do you want to make a codegolf competition? Or do you only want some tips? – Jakube – 2015-03-05T15:27:51.920
@jakube competition – Koray Tugay – 2015-03-05T16:10:33.993
2Then you should edit the question a little bit. 'Something similar to this' is very vague. I would formulate this in another way: E.g. Find the smallest power of two, that is
>= 100
. In this way the goal is more clearer. Also, I would generalize it to>= n
, wheren
is an input from the user (Not sure how to do this in assembly though). Otherwise someone will hardcode the solution 128. – Jakube – 2015-03-05T16:32:38.343