More Fun...

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

More Fun...

sarthak
I just completed the software hierarchy described in the book. I really enjoyed building all the software elements (assembler, compiler) but I think there are some gaps.
Suppose we built a machine understanding only machine code, if we want to write an assembler for it should it be written in the machine code too. How did we made the leap from machine language to assembly language? Similarly, should compliers be written in assembly language so that they can be implemented on our machine? I wanted to know how we implement a new language in any machine, I want to know what language the translator speak.
Reply | Threaded
Open this post in threaded view
|

Re: More Fun...

cadet1620
Administrator
sarthak wrote
I just completed the software hierarchy described in the book. I really enjoyed building all the software elements (assembler, compiler) but I think there are some gaps.
Suppose we built a machine understanding only machine code, if we want to write an assembler for it should it be written in the machine code too. How did we made the leap from machine language to assembly language? Similarly, should compliers be written in assembly language so that they can be implemented on our machine? I wanted to know how we implement a new language in any machine, I want to know what language the translator speak.
The Hack computer is a lot like the embedded systems I program in that respect. There are no compilers or assemblers that run on them. All the programs I develop for embedded systems are developed using tools that run on PCs, and only the machine code is programmed into the ROM on the microcomputers.

This thread has info about early assemblers.

These days we use tools to make other tools.

On your PC:
    Use a C compiler to write a Hack assembler.
    Use a C compiler to write a C compiler (c2hack) that generates Hack assembler.
    Use c2hack to compile itself and you get a C compiler that runs on the Hack computer.

This assumes that you've already written a lot of infrastructure for the Hack computer so that the standard C library functions are there...

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

Re: More Fun...

Lokesh Poovaragan
cadet1620 wrote
This assumes that you've already written a lot of infrastructure for the Hack computer so that the standard C library functions are there...
This line seems very interesting to me, could you expand a little on this topic? or point me in the general direction from where I can learn how to do this?
Reply | Threaded
Open this post in threaded view
|

Re: More Fun...

cadet1620
Administrator
Lokesh Poovaragan wrote
cadet1620 wrote
This assumes that you've already written a lot of infrastructure for the Hack computer so that the standard C library functions are there...
This line seems very interesting to me, could you expand a little on this topic? or point me in the general direction from where I can learn how to do this?
Start by learning a compiled language like C, and how to use the standard library functions. Learn and understand how the linker puts objects together with libraries to build executables.

My education is too far in the past to be able to point you at modern books. The classics for me were "The Design of the UNIX Operating System" and "4.3BSD UNIX Operating System". Look for modern books with titles like Operating System Concepts or Operating Systems Design. These will be very advanced books.

Reverse engineering is a great education. You can start doing that with Nand2Tetris. Look at the supplied OS *.vm files and figure out how to write .jack files from which the supplied compiler will generate .vm files that are identical to the supplied .vm files. Sys.vm and Array.vm are the easiest to reverse engineer. Memory.vm is probably the hardest, with Math.vm a close second.

I've never had to write an entire "standard library" that's an immense amount of work. I have written libraries to support custom hardware. I don't know of any books that specifically address library design and implementation.

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

Re: More Fun...

sarthak
This post was updated on .
In reply to this post by cadet1620
I read the thread you provided. Suppose I wrote my assembler in some high level language like perl/python and I want to run this on the Hack Platform. How will I do that? What tools will allow me to use this assembler on Hack Platform understanding only Machine Language?
Reply | Threaded
Open this post in threaded view
|

Re: More Fun...

cadet1620
Administrator
sarthak wrote
I read the thread you provided. Suppose I wrote my assembler in some high level language like perl/python and I want to run this on the Hack Platform. How will I do that? What tools will allow me to use this assembler on Hack Platform understanding only Machine Language?
This is not a practical line of inquiry for the Hack computer. It is akin to asking how to turn a bicycle into an automobile.

The hack computer architecture is not suitable for general purpose computing. The first thing that it would need is some way to program itself. That is, it needs some way to write to program memory. There is no way to do this in the current design. See Hack II: Escaping the Harvard straitjacket for a design mod I did to allow access to program memory.

A practical thing to try might be to research "Tiny BASIC" and write a Tiny BASIC interpreter in Jack.

Then you could write and run BASIC programs on Hack.

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

Re: More Fun...

sarthak
cadet1620 wrote
The hack computer architecture is not suitable for general purpose computing. The first thing that it would need is some way to program itself. That is, it needs some way to write to program memory.
I do not understand this point. Why would I need Hack Machine to write into its program memory? I want to run any assembly code on Hack-I. I wrote the assembler for this machine in perl. How will the Hack Machine according to you run that assembly code?

Reply | Threaded
Open this post in threaded view
|

Re: More Fun...

cadet1620
Administrator
sarthak wrote
I wrote the assembler for this machine in perl. How will the Hack Machine according to you run that assembly code?
What are you asking?

Q: How do you get the output .hack file from your Perl script running on your PC/MAC loaded into the Hack computer's ROM?

A: The .hack file written by your Perl program will be loaded into the Hack computer's ROM (in the CPU Emulator) by a test script or by the File | Load Program menu command.

Q: How do I run the Perl script on the Hack computer?

A: You can't; there is no Perl interpreter that runs on the Hack computer. Sombody (you!) would need to write a Perl interpreter in Jack.

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

Re: More Fun...

sarthak
In reply to this post by cadet1620
Thanks Mark, got your point on General Purpose Computing. Sorry for the confusion...