From ASCII to real binary values on hardware.

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

From ASCII to real binary values on hardware.

Victorrct
Hi,

I'm having some trouble understanding how the software hierarchy will work.
I understand the architecture and how the binary values in the ROM work, but I don't know how we go from a text file with machine code (.hack) to actually binary values in the ROM.
Because it's a text file, each "1" and "0" are ASCII characters.
So, how do we go from ASCII to real binary values on hardware?

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

Re: From ASCII to real binary values on hardware.

ybakos
True, an assembler typically translates assembly language code into binary. In our case, the translation from assembly (.asm) to .hack doesn't result in a binary file. This is so that we can read the 1's and 0's easily with a text file. We absolutely could write the assembler such that it translates each line of assembly into 16 bits.

To simplify, it's a matter of writing one's assembler such that, instead of writing the characters 1 and 0 to a text file, you write binary values to a file. Once the binary file exists, it's a matter of copying that data to ROM. (Mark may describe that process further, since he's got a lot of experience with hardware.)

Reply | Threaded
Open this post in threaded view
|

Re: From ASCII to real binary values on hardware.

cadet1620
Administrator
In reply to this post by Victorrct
Victorrct wrote
I'm having some trouble understanding how the software hierarchy will work.
I understand the architecture and how the binary values in the ROM work, but I don't know how we go from a text file with machine code (.hack) to actually binary values in the ROM.
Think of the output of the assembler as another intermediate "language". There is another tool that reads that language and loads it into the computer where it can be executed.

In a general purpose computer like a PC, the executable files are loaded into memory by a part of the operation system called a loader. In a ROM-based computer, the ROM is written using hardware tool called a ROM programmer.  

The "Load Program" command on the Hack CPU Emulator is the simulated ROM programmer.

There is often another step in the software chain between the assembler output and the executable files. A linker combines multiple assembler object files and libraries to create the executable file. To support linking, the object files contain additional information telling what external functions they need and what functions they contain that external functions can call.

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

Re: From ASCII to real binary values on hardware.

Victorrct
The Assembler that we will build will not be suported by the Hack platform, right?
Because it iscompiled to a different architectrue (for exemplo, x86).

So, am I correct to assume that the Hack computer will always be dependent on another computer to load the programs into the ROM?

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

Re: From ASCII to real binary values on hardware.

cadet1620
Administrator
The assembler that you build will write .hack files on your PC or Mac. The CPUEmlator, which runs on that same PC or Mac will be able to load these .hack files and run them.

If the Hack computer were a real piece of hardware, then your assembler running on a PC or Mac would be called a crossassembler, and another physical tool would be required to get the code into the Hack computer.

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

Re: From ASCII to real binary values on hardware.

cadet1620
Administrator
In reply to this post by Victorrct
Sorry, I think that I misunderstood your comment.

You are saying that the assembler that you write on your PC is compiled to x86 instructions, hence the assembler cannot run on a Hack computer.

That is correct.

Your Hack assembler is a crossassembler since it runs on x86 and generates Hack instructions.

If the Hack computer was expanded and supplied with peripherals like disk, and a way for it to program its own ROM, then it could run an assembler.  The current tool set: Jack compiler, VM Translator, Assembler, could be used to write that assembler.

Its an interesting process to develop the first tools for a newly designed processor.

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: From ASCII to real binary values on hardware.

Victorrct
In reply to this post by cadet1620
Thanks, that makes sense.

Just to see if I understand:

Suppose I wanted to physically build the Hack computer and a way for it to program its own ROM.

I would have to create a program that translates .hack into .exe (this program is called a linker), and a physical tool that loads the .exe file into the ROM (a ROM programmer).

First, I use the PC to create a linker that will work only on the PC.
The .exe file, produced by this linker, is compatible with the Hack architecture, but not with the PC.
But, the linker (which is a .exe file itself) will only work on the PC. ("cross linker").

So, the Hack computer would depend on this linker, therefore, it would still depend on the PC.

For the Hack to be independent, we could develop another linker that would work on the Hack platform.
We do this by programming it in some language.
But we don't compile it to a .exe that will work on the PC.
Instead, we compile it to .hack and use the previous linker to produce a .exe that will work on the Hack platform.

Finally, we use the ROM programmer to load it into Hack.
Then, the Hack would have its own linker working on its platform.

We could use the same process to build an Assembler (and all others translators) that will work on the Hack platform, instead of a cross assembler.


Is this reasoning right?

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

Re: From ASCII to real binary values on hardware.

cadet1620
Administrator
Yes, that's the overall picture.

There are a lot of details that would need to be worked out to make a useable general purpose Hack computer, starting with writable code memory so that programs could be loaded from a storage peripheral (disk, etc.).

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

Re: From ASCII to real binary values on hardware.

Victorrct
Thanks! This was helpful.

Victor