SumtoN - Hack Program

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

SumtoN - Hack Program

Anne
Hello - I am currently studying for an upcoming exam on computer structures and operating systems and I tried to run this program (as seen in the coursera Nand2Tetris course), but it constantly gives me the following error:
Jump Directive Expected

I´m using this code with the CPU Emulator.

//This Program computes RAM[1]= 1+2+...+n
//Number n is stored in RAM[0]

@R0
D=M
@n
M=D //n=R0
@i
M=1 /i=1
@sum
M=0
(LOOP)
@i
D=M
@n
D=D-M
@STOP
D;JGT //if i>n goto STOP
@sum
D=M
@i
D=D+M
@sum
M=D //sum = sum +1
@i
M=M+1
@LOOP
0;JMP
(STOP)
@sum
D=M
@R1
M=D   // R[1]=sum
(END)
@END
0;JMP

Thank you so much in advance!!
Reply | Threaded
Open this post in threaded view
|

Re: SumtoN - Hack Program

ybakos
Anne, what is wrong with this line:

M=1 /i=1

Reply | Threaded
Open this post in threaded view
|

Re: SumtoN - Hack Program

Anne
Thank you!! Sometimes my own blindness baffles me..