Pong.asm Comparison error

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

Pong.asm Comparison error

Maesltrom
Hi guys!

I'm having troubles with the "sys.init" variable in the line 150 from the Pong.asm
"
@R13
M=D
@sys.init
D=A
@R14

"
Due it's the first new variable in the program, I'm getting the value: "10110" as its address but the output must be "0110100110110010" a number much greater
Can anyone explain to me why this variable has this value?
Reply | Threaded
Open this post in threaded view
|

Re: Pong.asm Comparison error

cadet1620
Administrator
sys.init is a code label in the Sys.vm file. Make sure that you have copies of all the OS VM files in the directory with the Pong VM files when you run your VM translator.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Pong.asm Comparison error

Maesltrom
Hi Mark!
VM emulator is the next chapter yet. And i know nothing about it
Maybe i could add this label in the predefined variable table.
Reply | Threaded
Open this post in threaded view
|

Re: Pong.asm Comparison error

cadet1620
Administrator
Sorry about that; I missed which project you were working on...

'sys.init' is a code symbol defined on line 27916 of Pong.asm.  I don't see an obvious reason for it to not be in your symbol table. Maybe you have a problem with long source files or a limitation on the number of symbols you can support?

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: Pong.asm Comparison error

Maesltrom
Hi Mark!
The trouble is: "sys.init" is lower case and in the hack specifications lower case is used in variables and upper case to labels. The chapter 6 pdf tells nothing about these VM's variables.
I will change my program and make it treat names starting with "sys." as labels.
This is the solution right?

Thanks. You opened my eyes =D
Reply | Threaded
Open this post in threaded view
|

Re: Pong.asm Comparison error

ybakos
Not quite.

Labels are defined as some "stuff" between parenthesis. When your assembler encounters such a symbol on its first pass, it should add the "stuff" between the parentheses to your symbol table and correspond with a number representing the instruction (ROM) address  (hint: this can be slightly tricky if you forget that labels do not generate a line of instructions).

During the second pass, your assembler should replace all occurrences of symbols with numbers, when generating the hack machine code output.

There are some predefined symbols like R0, which your assembler should "know" is a symbol that maps to the number 0, representing the data memory (RAM) address.

When your assembler encounters something like @sys.init, it should generate an A instruction, which would be a 0 followed by the binary representation of the number that sys.init corresponds to. Where does that number come from? On your assembler's first pass, it should have encountered the label (sys.init), and added sys.init to its symbol table.

Does that help?
Reply | Threaded
Open this post in threaded view
|

Re: Pong.asm Comparison error

Maesltrom
This post was updated on .
I have have the same question. This is strange because I don't check if the labels's names are in upper case. Anything between parentheses must be treated as labels. I will check the program when I get in home.

The trouble now is: @sys.init appear before (sys.init)

Thanks guys and you helped me a lot ybakos
Reply | Threaded
Open this post in threaded view
|

Re: Pong.asm Comparison error

Maesltrom
Done! To solve this trouble i add one more pass in the code. Now the program first search for the L's instruction then search for the A's instruction and then convert the file to binary.

Thanks Mark
Thanks ybakos

And the next victim is: Virtual Machine