Can I override labels in asm?
For instance lets say I have a label called label1 and later on I want to declare this label1 again but use it as it points to a different row.
Let's assume that this was possible. Consider the following code snippet:
@ label1
0; JMP
...
(label1)
D=1
@ end
0:JMP
(label1)
D=-1
(end)
...
So this code always jumps to label1. But which instruction does it jump to?
A label can be used anywhere in the program, even before the place where it is declared -- that's how you are able to jump forward to skip over code, a behavior that is necessary to perform selection operations.
You could probably define a protocol where label has different values in different portions of the code, but it would be confusing. For instance, what is the value of label1 from the beginning of the code up until the first time it is defined? That would be a special case that would not apply to every other time it is defined.
The reason I ask this is becausr I need to make the eq in the vmtranslator so I was lookibg for a way that i dont need a way to like count the labels every time im using the eq command
No way around that. Labels are global (and need to be in order to work). For them to be local, you need a means of defining scope -- but that is a higher-level construct that the VM language barely implements.
Dealing with "local" labels is actually very easy.
Just have a function called something like nextLocalLabel() that maintains a static counter and when you call it, it returns a string suffixed with the count value. Something like "localLabel:37"