How do you write a machine language?

bi
16

If I understood correctly, the first computer program was written with a machine language because there were no programs to write a program before. But how exactly should one imagine this?

Is machine language a code? And would it be possible today to buy a proto-computer and program it with a machine language? How do you enter this language? Would this computer have several million switches that can turn any transistor in the processor on and off? Are such proto-computers still being built? I assume that you can own a modern laptop no machines language.

Is it possible to compare the development of computers with metalworking? If you want to make a screw, you inevitably need metal tools. These can only be produced with other metal tools. This always goes back to the past to the first metal tool, which was built with stone tools.

If I want to build a screw today but only have stone age tools, it would take me about 10,000 years to develop a lathe and tappers.

Today, it would take about 80 years from the ground up from a proto-computer with machine language up to Windows 10 to program it. So without the help of other software?

Lo

The machine language is actually not that complicated. The "simple" components are hard-wired circuits, the machine language consists of instructions that are then executed by these hard-wired circuits

Examples of very simple circuits would be something like

AND
OR
EMERGENCY
NAND
NOR
XOR
Multiplexer, demultiplexer, adder

So examples of machine language code would be:

Load the value from memory address XYZ
Load the value from address ABC
Add the last two loaded values
Write the result of the addition to memory address ZZZ

Based on this you can then develop compilers for "higher" languages

If you had to redevelop Windows 10, you'd probably need five years if you had the right developer capacity, if it were done here in D, probably 25 years and a few trillion euro 🙈

ru

To understand this, you should look at how a processor works.

Anyway, he can do a lot of simple commands. For example, Transferring a number from one register to another, adding two registers, etc. Each of these instructions is represented by a particular bit pattern, which can be used as a binary or also as a binary. Can write hexadecimal number. One consequence of such instructions is a machine language program.

In order not to have to remember these numbers, they have created the so-called assembly languages. Each machine command is given a human readable name ("mnemonic"), e.g. "ADD X, Y". These mnemonics can be manually translated into machine language with a table, or left to a program called assembler.

You can also program a modern PC in assembler or machine language. Also, a high-level language compiler (e.g., C) generates machine language programs. Even a modern CPU can only execute machine language.

gr

Of course, you can also use machine language on a modern laptop. A Windows program usually consists of machine code. This code was generated by a compiler. https://de.wikipedia.org/...i/Compiler

You can also type in machine code by hand. That would be very tedious and would take much too long.

On very old computers, the code was punched on punched cards and then read in.

bi

So today there are such "circuits" for typing, that is to say systems to buy?

Lo

What exactly do you mean? You can buy a CPU ready, otherwise you can of course the individual components such as AND, OR, adder, etc. Also buy and wire individually… You must then provide a clock, connect to a memory, Ultra simple input / output -Components for Interaction / Programming, etc. -

or do you only want to program in machine language?

bi

But on a modern laptop one could only write a machine language with the help of software.

My question is rather, if there's a system with which one can manually turn on and off individual transistors in the processor without software.

The first computer program was finally written without software.

gr

No, they were loaded into the RAM via a punch card reader. There are not individual transistors on and off by hand.

Fe

Yes, you can find these switches today in every PC's BIOS. This is a chip that contains instructions on how to handle the computer's hardware and load the operating system.

bi

I myself do not want to program a machine language. I'm only interested in how such a system would look like. So an interface with which one can manually switch a processor. And whether such simple systems are still being built today. Because eigt you do not need these systems today.

Lo

They have never been instructed by instruction by hand, switching through billions of times per second. They always run with a given program

The most basic system would really be a punched card, but executing the commands on the punched card is physically wired. However, with a punch card, you can really do individual instructions

Fa

This is a very comprehensive topic… Just a short answer from me:

Machine language is a binary code. This is different for each processor architecture (e.g., Intel / AMD as in the PC or ARM as in smartphones). But there are tables.

A command such as "Add R1 and R2, Write result in R3" then becomes, for example, the binary code: (conceived coding)

0011000100100011

0011 => Add command

0001 => 1st operand

0010 => 2nd operand

0011 => 3rd operand

So one thinks of a program, e.g. R3 = R1+ R2 and then translates that piecewise into such a binary code.

The problem is getting the code into the computer. I would guess that this is no longer possible with modern computers. However, I once saw a project on the Internet, where someone made for a simple microcontroller (quasi mini-mini computer) … There, the program is loaded, in which there's a clock line and a data line. Whenever the clock line changes from 0V to 5V, it is checked whether there are 5V (1) or 0V (0) on the data line. So he needed 2 switches, which he used alternately.

Your question mentions another problem. Computers can only execute machine commands, for simplicity they have developed programming languages … These translate the programming commands into machine instructions. (The program is called a compiler) Of course one programs the compiler also in a programming language - and not with machine code. But that means - since the very first compiler was written in machine code, there's a chain of dependency… I only heard that a professor was working on this dependency chain. - What exactly, I do not know.

gr

In this video you can see an Altair 8800 computer where machine code is loaded into the RAM via tape and then started. The computer then prints a message on the printer. That's how it worked with computers from the 1940's and 50's.

gr

Incidentally, the video also shows that the first few bytes of the machine code had to be entered manually by switching several switches. The rest was then read from the tape.

bi

Yes, I wanted to go out on this chain of dependency that you mentioned. That is why the comparison with metalworking. If all the metal tools of today were gone tomorrow, then we would have a big problem and have to start everything from scratch.

Hence the consideration of whether one still writes and stores machine codes for compilers.

Fa

You do not have to write the machine code yourself, but it is automatically produced. Compared with the tool: The mold is milled, so no need to build it by hand.

One would have to pick it up for your scenario on paper, or create opportunities to load the program into the computer… Professionally, no one will deal with it, but in the hobby area, there's everything - self-built CPUs or whole computers, own programming languages, own input options. Much of the knowledge is still there in paper form. I also found it exciting to read in books from the 50s how computers work, or to build very simple computers with 4 relays and mechanics.

Apart from that I'm of the opinion that a modern complex CPU like Intel / AMD no single person understands in more detail. Sometimes the commands are not executed in the right order, but somehow - and the result is corrected at the end, etc…

Me

As an exercise you could write your own little virtual machine in a programming language of your choice. This is much easier than it sounds, so do not confuse the term "virtual machine" with huge software packages like VirtualBox or VmWare or anything like that.

A simple VM written in C fits on a single screen page. A pretty powerful VM in C ++ with stacks, registers, and more. Fits on three to four screens or A4 pages. With the latter you can then do really complex things, such as develop a scripting language for games, implement a comparatively difficult to crack copy protection, etc.

If you are unfamiliar with low-level languages such as C, C ++, Pascal, or even Assembler, you can even write a VM in scripting languages such as Python, Ruby, Perl, or PHP, but even languages in managed environments can do that realize: Java, Kotlin, C #, VB.net, etc.

So, once you understand what Assembler means and build a small VM, there are no questions left. But do not go crazy if that does not work the first time you try it! Everyone starts off small, and even a simple VM requires a bit of programming. Understanding.