Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does hardware run assembly? How was the first assembler written?

Tags:

assembly

Having taken a course on compilers and making a rudimentary one by myself, i still have this lingering doubt about the first compiler.

From a high to low level, i see code running in lets say C or C++ which gets converted to the respective assembly language equivalent by it's compiler (lets say gcc). This code is platform dependent (lets say i'm on intel x86 architecture).

Now comes the question, how does a hardware run assembly?

I remember from my computer organization class that each and every assembly statement gets converted to a specific format (depending on the processor) for example, a statement like mov ax,bx gets converted to it's opcode let say 0110 101010 101000. Assuming the assembler parses every statement in my assembly language program and converts it into a machine code, then how was the first assembler written?

like image 952
user720694 Avatar asked Aug 17 '12 14:08

user720694


People also ask

How was the assembler written?

There's nothing special about how an assembler is written. All it does is parse an assembly syntax and spit out machine code for a particular architecture. If your preferred programming language can read text and write binary, you can create an assembler with it. Save this answer.

How was assembly language coded?

Assembly Languages It uses short codes to instruct the machine to perform certain operations. Whereas machine language uses 0s and 1s to instruct the computer, assembly language uses mnemonics that are easier for humans to work with. As we already know, processors only speak machine language.

What was the first assembly language?

What was the first widely used programming language? Assembly Language appeared in 1949 and soon saw wide use in Electronic Delay Storage Automatic Calculators. The Assembly was a low-level computer language that simplified the language of machine code ie. the specific instructions necessary to operate a computer.

What comes first assembler or compiler?

Before the compiler can successfully execute the code, the errors must be removed from the source code. Example of compiled languages is C, C++, Java, C#, etc. Compiler converts the source code written by the programmer to a machine level language. Assembler converts the assembly code into the machine code.


1 Answers

Actually I think you understand. First off the title question, how does hardware run assembly. Hardware runs on machine code or machine instructions or whatever term. As you have correctly described assembly is a representative of that machine code, and not always but is close to a one to one relationship one asm instruction to one machine instruction. These being bits, ones and zeros, the hardware can now perform the actions that the bits describe.

Now how is the first assembler written? With pencil and paper. You typically write down the instruction in some sort of pseudo assembly as you may not have completely defined the language, and then you write down the bits based on the encoding, the same thing an assembler would do. Then using some mechanism you feed those bits into the computer and tell it to run.

Eventually, naturally, this becomes tedious for larger programs so you decide to write a larger program that parses a language that is easier to write, then repeat that with more complicated languages and programs.

Even today depending on the team and how they do things and the individual engineer testing the instruction decoder, etc. Writing machine code by hand still happens. Eventually the assembler is created and you switch to that and sometimes there is a higher level compiler and you switch to that for the bulk of the coding, but in the chip development world you still are very aware of and from time to time will modify the bits of an instruction at the machine code level.

like image 90
old_timer Avatar answered Jan 01 '23 22:01

old_timer