Where's "foo"?
Should be something like:
mov cx,5
foo:
;do stuff
loop foo
Question
I've built an assembly program and when I try to loop a label, compile (with 0 errors) and execute, I get this error :
ntvdm cpu has encountered an illegal instruction
So I remove the code into the label, but i still get that error! And if I remove the loop statement, the program works
Haven't the loop statement the following sintax?
mov cx,5
loop foo
;execute foo 5 times
La solution
Where's "foo"?
Should be something like:
mov cx,5
foo:
;do stuff
loop foo
Autres conseils
An alternative to loop is jmp
statement, which has many types eg: je , jg , jnz , jz e.t.c.
mov cx,5;let you want to loop 5 time, move 5 in cx
jmp foo; jumping to foo
;some stuff if you want
foo:
;do some thing you want
dec cx;decrease cx by 1
jnz foo; jump to foo if value of cx is not zero
; when value is zero loop will end,any thing further you want to do after loop will comes here