How does jump works?

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

How does jump works?

bamar
I mainly understand how jump works. What i dont understand:

@10
0, JMP

this is an infinit loop if @10 is in the 10. and also the last row of the program. the program will get the 10. register, which is the 10. row, and jump to it.

i create a new variable:
@temp

the translater will translate it to @16 - which is register 16.

what if the code has more than 16 rows? what if i want to use @16 and also @temp in the same code? how is this works out?
Reply | Threaded
Open this post in threaded view
|

Re: How does jump works?

WBahn
Administrator
I don't really understand what your actual question is.

When you perform a jump, the next line of code to be executed will be the instruction in ROM whose address was in the A register at the time the jump was performed. How a jump is performed is simply by loading the contents of the A register into the Program Counter.

It really is that simple.

Variables are intended to be RAM addresses where certain pieces of data are stored. They should NOT be used as ROM addresses (i.e., targets for jump instructions). The assembler doesn't care one way or the other, but it is asking for trouble to do this.

ROM addresses should be defined via labels. When you define a label, such as (END) is associated the ROM address of the next instruction with the label. Then you can load the label into the A register using @END.

Not only does this make your code much more readable, but if you modify the code that changes the ROM address of the target instruction, the value associated with the label will automatically change to reflect this. It is VERY poor practice to jump to a hardcoded numeric value unless the address of that target location truly will never change.

As for using @16 and @temp in the same program. Sure, nothing prevents you from doing that. At the end of the day, every @ instruction becomes an integer constant. The assembler simply maintains a table of strings and the numbers associated with them and merely replaces each occurrence of each string with that number. It neither knows nor cares if other strings happen to map to the same number or if that number happens to be used directly someplace. But any time you are referring to the value associated with the temp variable, you should use @temp. But if you need to us 16 for some reason unrelated to the variable temp (say multiplying pounds by 16 to get ounces), then you should NOT use @temp just because you happen to know that it is equivalent to 16. What happens when you add a new variable earlier in the code and it get assigned to RAM[16] and now temp is assigned to RAM[17]?
Reply | Threaded
Open this post in threaded view
|

Re: How does jump works?

bamar
thank you! i missed ROM and RAM. I knew there should be something different between the two way of useing. now everithing is clear :)

jump uses the ROM addresses, and variables created in the RAM, that what i was mixed together.