Welcome to the perspective unit of week 4 in which we introduce the machine language and load some low level programs in the Hack assembly language. So one question that normally comes up is how does the Hack machine language differ from the machine languages of typical computers like personal computers? Well the Hack machine language is very simple because it is designed to operate on top of a very simple hardware platform. And we built this computer in purpose as a very simple architecture. Because we want to, to be able to actually build it in, you know, in the a space of a six weeks course and therefore the computer is very simple, but it sufficiently powerful to to offer almost everything that you need for reasons that I will e, explain in, in, in just a minute. So, typical machine languages are much more rich than the Hack instruction set. They offer more commands more instruction types more data types, like floating point and more operations, like for example, multiplication and division. And yet, as I said before, there’s no need to worry because all these fancy things that other languages offer can be delivered at the software level at a higher level of obstruction and that’s exactly what we’ll do in the second part of this course. In Nand2Tetris part two, we build an operating system, and we introduce all sorts of operations that are currently not supported by the machine language. So, here's the next question. It looks like in the Hack language, whenever you want to do something meaningful, you need two machine language instructions. One to address the memory, and one to operate on the selected memory register. Is this the standard way to do things? Norm? >> Well, most machine languages are more sophisticated, more powerful than ours and usually do allow you to specify both operator and operand in a single machine language command. For example, you can say I want to add and I want to use this memory location and put if all on a single machine language instruction. Now in our computer, in the Hack computer we only have 16-bit i, instructions and in 16 bits it's very difficult to put both both a lot of information about the operation and a lot of information about the operand. In particular, you can't put a whole memory address as well as more information about what kind of operation you want to do. So in our situ, in our case, you have to split the point where you specify the address, which requires 15 bits of its own, and the place where you actually specify the operation, which requires a few more bits. In other machine languages, some, usually, they have wider machine instructions, or sometimes even variable with machine instruction, and then they could fit more information into a single machine instruction. That said, the basic idea of taking part of the, of the, of the address on which the machine operation is supposed to work on, taking part of that address from a previous command is not an unusual kind of thing, and many machine languages do have that. >> So a related question that we often get is that the Hack machine language indeed has some strange or peculiar syntax rules. Can you say a few words about the the choice of this syntax and how it differs from the syntax of regular machine languages? Well, unlike high-level languages like Java machine languages are not designed to make people happy. They are designed to operate on harder platforms. So the commands of machine language must deal directly with the LU, with the memory, and the registers. And they must be extremely efficient. And that's one reason why machine languages are so simple, as we discussed before. So as we said before the Hack machine language is is very simple. And and therefore, we also decided to make the syntax somewhat simpler than the, what you normally find in in machine languages. For example, if you want to compute addition and store the result in some register, in the Hack language, you say something like D equals D plus M. Whereas in a normal machine language typically commands like this start with the, the specification of the operator, normally you will have something like, ADD D along with some address. And you can specify both the address and the register of the destination and the op, the opera, the operator in one instruction, because normally, in machine languages, you have 32, 32 bits or 64 bits. So there's enough space to pack all this information into a single command. Whereas in Hack, we do only this. Likewise, if you want to put the contents of one register in another register, in Hack you say something like D equals M, for example. Whereas in a normal machine language typically you would say something like LOAD D, M or something like this. And once again, instead of M you can write an address and pack all this information into a single instruction. So the last question in this perspective unit is do people actually have to go through the trouble of writing programs in machine language? Well, the answer is that people don't really write programs in machine language. Instead some developers sometimes write programs that generate machine code, and these programs are called compilers. And a compiler is a program that takes another program written in some high-level language like Java and translates this program into binary code. So in order to write a compiler, obviously you have to understand the machine language that the compiler has to generate. And that's exactly what we are going to do in the second part of the NAND to Tetris course, where we actually write a compiler for a high-level language. And this compiler will generate a Hack code that runs in the machine that we build in this course. Now, there's one exception to what I said before, and that is that in some applications, in particular, in real-time systems or in applications where performance is incredibly important programmers sometimes have to look at the gory details of the machine language code if they want to optimize their programs. So they don't try the programs in machine language. They write them normally in, in, in a language like the C programming language but once they translate the program into machine language, they look at the code and if the code looks terribly tangled or unnecessarily long, they can go back and and rewrite their high-level code. But in the most part most most programmers writing high-level language, and that's it.