If you want to know how to create a compiler you should have a full understanding of your Central Processing Unit (CPU) and machine language. What does that mean you might ask? Why, you could also ask? First you must know the capabilities of your CPU. If you don’t, you have no idea what the CPU can or can’t do! Studying an assembly language will not hurt either. In fact I recommend it! Let me explain if I may have some of your time.
First you should know that some of this information I am using to write this blog post comes from books dating back to 1985. Yeah, that’s right. Some knowledge you will gain if you go to college for computer science will be from the history of computers. But sometimes they miss the good stuff. Besides I have a love of books and knowledge so when I saw the books cheap at Thiftbooks.com and Amazon.com I jumped on them. Why? Because the up-to-date version, if you can find one, is about $45 to $175.
One of the books is Assembly Language for the PC. In this case the Intel 8086 Microprocessor. So I decided to have a look at the semantics sheet for the 8086. The assembly language is a compiler that will change your input to machine language. You can still buy an 8086 Processor on eBay used for $12. What did I learn from the semantics sheet? First off, I do not have an electronics engineering degree nor do I understand all of the semantics sheets. There was a printout PDF that was about 30 pages. You have the input/output pins labeled and the power and negative pins as well. Which you need to know to program and know how to change it to machine language. As you read the semantics sheet you begin to understand what the processor can do. It has a 14 Word by 16-bit register set. A Word is 16-bits so this means the instructions set can handle a 14 Word by 16-bit Register set. If I am not mistaken, that is 3584 bits of information the processor can handle at any given time.
I also printed out the semantics sheets for the 80186 Microprocessor which is also in the 8086 Intel family. When building on the 8086 processor family they used the same instruction set and added ten new instruction types to the 80186. Also the object code in the 80186 is compatible with the 8086/8088 microprocessors. I have to know if you are still wanting to know why having knowledge of your processor’s ability and assembly language are needed? Well, knowing that the 80186 Intel Processor only handles 16-bit registers is important.
I will be talking about the 80186 processor from here out because it is more advanced in the 8086 family and is cheaper from some vendors. Knowing that it only has 16-bit registers to work with is a key factor here. You have to think of it like a limited text field that you can only put in 16 characters. Why? It’s the same theory. You can push or pull ( send to or receive from) from each register to your RAM or random access memory.
So the point to be made is that when you want to create a low language level compiler you want to download your hardware semantics sheets. Why? Because compilers use assembly language and to write the language your compiler will accept you need to know what your computer hardware will do. You need to know the address to your registers as well. Since the compiler uses assembly language to write instructions to the processor and it sends them to the RAM for output it also uses that assembly language to get input from the mouse and keyboard.
Many of you are used to what the higher end programming languages do and look like. In the lower level languages I have seen you don’t do much more than put in the registers and take what you put in them and send it to RAM. Maybe this will help, rewriting the assembly language is like rewriting the kernel of your operating system. By changing the assembly language you change what compilers understand from the machine code. My question is, was the assembly language updated when it went from 16-bit processors to 32-bit and on up to 64-bit processors. For the most part the answer is no!
If you are wondering why that would be important, well, it comes down to this, the 16-bit registers on the old technology has only increased to Double Word 32-bit registers even on the 64-bit architecture. Based on information from the Datasheet Vol. 2: Intel Core i7 processor when you try to access information larger than 32-bit you get unexpected behaviour. My guess is that would be because the assembly language is not receiving and transferring more than the Double Word or 32-bit values. So my point that you would have to rewrite the assembly language is right! You will have to write the assembly language compiler to accept say 64-bit values. In my blog discussing the invention of the 128-bit processor you could write the assembly language to go up to 128-bit registers to get the most out of the technology.
Since we are just starting out in our processing technology, let’s get back to the 80186 Microprocessor. I know some of you are asking, what can you do with it? Well when you build your old vintage computer you can run MS-DOS and play some old games or write a simpler program for that 16-bit processing computer! Sounds exciting right? Okay maybe not so much. But remember Windows 3.0 was programmed on one of these processors if I remember correctly.
Plus the age, size, and cost makes the 80186 processor a cheap possibility to build a computer to get the understanding you need in computer science as a hardware engineer and designer. Interested in building a computer like that. Check out Ben Eater’s “Build a 6502 computer” video series where he builds on with the 6502 8-bit processor. Are you ready to learn to program but not ready to build your circuit board computer? Then you need to buy a cheap Arduino board or kit to learn how to make the processor do what you want it to do. You can use an Arduino microcontroller board to learn assembly language input/output. That will get you some understanding on how to write your assembly language for the 128-bit computer we are working on.
I am learning to program in C++ which I will be using with my Arduino that is coming in the Snapino Snap Circuits kit I am getting from Amazon. Why a kids programming kit? I am Currently in a group home that I can’t even get my own computer!?! Which sucks but at least they let me have the Snapino and a Snap Circuits Extreme Kit to add to the fun. I hope to learn programming assembly language input/output to build up to programming my own computer chips. The Snapino kit with the extra Snap Circuit kit will give me some capacitors, resistors, and transistors to study how the 1s and 0s move through the board. I have future plans to write the compiler needed to create the assembly language for the 128-bit computer as well. Now I hope that I haven’t left anyone in the dark or lost in this blog post. Have a Blessed Week!!