Assembly using Python

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

Assembly using Python

eVh1955

Hi.  Please critique my flowchart in the attachment.  I have not converted into boolean yet.  I will make another one later.  Thanks.

I converted copies of .asm files into .txt files.  

HACK_parsing_flow-chart_using_Python.xml

I have read that there is already a built-in parser function in python.  Has it worked well for you?  Is it more convenient than what I am working on right now?  Please let me know!

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Assembly using Python

WBahn
Administrator
If you just use the parsing tools of some language, then you rob yourself of a significant objective of the project which is to learn and understand how to parse a language.

For the assembler the task is very easy since each line is its own instruction. On top of that, each C-type instruction consists of four independent pieces. The first is just because it IS a C-type instruction while the remaining three match directly to the three possible parts of such an instruction.

If you don't spend the time to learn how to do this yourself, you will be completely lost when it comes time to parse the Jack language. If you just use someone else's parsing routines, then what's the point of doing it at all?
Reply | Threaded
Open this post in threaded view
|

Re: Assembly using Python

eVh1955
Hi.  Could you clarify for me what to put on the symbol table.  We have a partial .asm code here:

   @OUTPUT_D
   0;JMP            // goto output_d
(OUTPUT_FIRST)
   @R0            
   D=M              // D = first number
(OUTPUT_D)

I understood that in an @variable, the value should start at 16.  If OUTPUT_D is the first @variable, its value should be 16.  But what value should I put in for (OUTPUT_D)?  16, or the position of its line?  Thank you.  
Reply | Threaded
Open this post in threaded view
|

Re: Assembly using Python

WBahn
Administrator
Remember what the purpose of a label is.

If a label is used in an A-type instruction and this is then followed by a jump that is executed, code execution should continue with the first instruction in the code following where the label was defined.

So the value associated with a label must be the ROM address of the first instruction following the label definition.
Reply | Threaded
Open this post in threaded view
|

Re: Assembly using Python

eVh1955
Hi.  I was able to create a parser using Python.  My platform is jdoodle.com.

It accepts an .asm file and writes a binary form of the former in a .txt format.  I have to save it again as .hack in Notepad before I compare them to the assembler.

The problem is, the assembler keeps on saying that Line 1 is over 16 characters.  Yet this is not the case...



binary_output(1) is its original form.  I have to enter each item again and again until each line is 16 characters long.  I save it as binary_output.hack in Notepad then feed it to the Assembler.

Unfortunately, Assembler keeps on saying that Line 1 is 16 characters long.  I have checked it again and made sure there was no backspace, but I still got the same results.

How do I resolve this?  Thanks.
 
Reply | Threaded
Open this post in threaded view
|

Re: Assembly using Python

WBahn
Administrator
Is there a blank space at the end of each line? If so, try removing that and see what happens.

Another possibility is that the text encoding that is being produced is Unicode and not ASCII.

How many lines are in the .hack file? How big, in bytes, is the file. If you are on a Windows platform then it should be right at 18 times the number of lines. If you are on a Mac or Linux box then it should be about 17 times that number. If you are getting close to twice that size, then it is probably using basic Unicode.
Reply | Threaded
Open this post in threaded view
|

Re: Assembly using Python

eVh1955
This post was updated on .
Never mind.  I used another program similar to Notepad.  Sublime is a better alternative.  I have just finished Part 1 of the Nand2tetris course and received a certificate from Coursera.  

I am still thinking of either going to Nand2tetris Part 2, MIT's Discrete Math (not an online course, but they have an online library where I can go to), or Stanford's Algorithm class also in Coursera.  I am confused at this point.  How would you order the classes to take, or what can be taken at the same time?    

I am using the curriculum of
https://github.com/ossu/computer-science

I have already finished all three Calculus courses in edX, and took Multivariable Calculus and Linear Algebra at Imperial College London's online courses in Coursera.  

Thank you for your help in helping me get through this course.          
Reply | Threaded
Open this post in threaded view
|

Re: Assembly using Python

WBahn
Administrator
I don't see any conflicts between the N2T Part 2 and anything else and there's something to be said for pushing on while Part 1 is fresh in your mind.

I don't know about the Algorithms course and whether it might benefit from having Discrete Math first. But probably not very much, so I don't think the order you take them in matters and you could likely take them all at the same time provided that would be too much of a workload for you.