How does a assembler (at very basic level) work in translation of Assembly language to machine code ?

[What my understanding is that when a Programme is written it is written in text and then assembler converts these "texts" into bits which computer understands . So for example if I wrote MOV A, B this will be saved in memory with the help of "keyboard"( in 0s & 1s which are basically electrical pulses). Now as these saved bits will be containing bits corresponding to alphabets like 'M' ,'O' 'V' (The ASCII code) so and so on .Now what assembler will do is to compare these bits stored in the memory ( which are corresponding to the "texts") to the bits already stored in "assembler". So the text bits ( MOV…) will match to some of these assembler bits ( out of lots of bit groups which are related to other key words like MVI ,ADD ) and as a result of these comparisons it will give "opcode" relating to “MOV” text. Am I right or is this a wrong way of thinking? ]

  • \$\begingroup\$ Go to Antoine VIGNAU and Olivier ZARDINI's web site and read the pages there as well as download their source code. That assembler source is fully available, is relatively simple, supports relocatable objects, and does all the needed linking steps as well. It's all-in-one. Can't beat that. Reading the code will answer all your questions. See: brutaldeluxe.fr/products/crossdevtools/merlin (go to very bottom of page for icon to use.) Or visit: infinitefactors.org/jonk/patch.html for a modified version of it. \$\endgroup\$
    – jonk
    Oct 3 '17 at 14:56
  • \$\begingroup\$ Example: when I type MOV A, B in RAM :'M' >> some bytes (ASCII CODE) in memory (RAM)in form of 0v and 5v (voltage may be different but you know what I mean) 'O' will be saved same & so V , A , "," , B .Now the programming software also have the part in RAM which we call "library" saved in 0s & 1s in the form of 0v /5v.So my question is that does "translation" mean that typed the 0s,1s of MOV A,B will be compared to saved 0s and 1s (library's)by logic ckt & then depending on the matching or mismatching of those 0s,1s will result in another 0s,1s (opcodes,will be stored & executed in RAM)? @jonk \$\endgroup\$ Oct 5 '17 at 7:22
  • \$\begingroup\$ An assembler just processes tokens and generates files. Sometimes these are object files. Sometimes they are binary files. Depends on what you want to do. Either way, they are just "data." A different device entirely reads up a binary file, for example, and transfers that data into a hardware device (like a ROM or the flash memory of a microcontroller.) How that is achieved depends on the device. Some devices require 12 or 13 volts to write data, even though they operate normally at 5 V. Other than that, I'm not sure where your head it at so it is hard to know what to add. \$\endgroup\$
    – jonk
    Oct 5 '17 at 7:26
  • \$\begingroup\$ I just want to get insight in what actually happens in RAM when people say that " Assembler translates the assembly language to machine language" at circuit level in simple words .It may not be very technical but logical . \$\endgroup\$ Oct 5 '17 at 7:34
  • \$\begingroup\$ Without the technical verbage, and avoiding fancy features, "the assembler converts source code into a sequential series of byte values, of length N bytes, that are transferred into some memory starting at some address and continuing for N memory bytes." \$\endgroup\$
    – jonk
    Oct 5 '17 at 7:39

Actually it the 'conversion' between the user-typed text file and the actual (binary) assembly/executable code is done by a special program, called an assembler.

It is a text parser, that parses all text in pieces (e.g. first 'MOV', than its operands/arguments. One by one it is translated (and items may be stored if needed).

Parses are based on rules, so e.g. if 'M', 'O', 'V' is found in a text file, it knows it has to be translated to e.g. opcode 0x40. And also it knows what to expect afterwards (arguments). If these are correct those arguments will be translated, otherwise an error message will be shown.

Also optimization is done within the assembler, and other settings affecting the binary code.

Update (according comment):


  1. The user creates with a text editor the assembly code in text form (e.g. with commands as text like MOV 1, A, SUB ...
  2. This is saved to disk to a file, e.g. program.a
  3. The user runs an assembler program
  4. This program reads file program.a to memory.
  5. It translates word by word and operand by operand the text using a parser. The text is translated into opcodes and operands.
  6. Mostly there is an optimization step that removes unnecessary opcodes or changes them into better/faster ones.
  7. These opcodes and operands are stored in another file, e.g. program.exe (the executable).
  8. When running the program, the program.exe file is read into memory.
  9. The computer/microcontroller executes the code in memory.
  • \$\begingroup\$ it looks like my understanding written with question is correct. Is it? :P \$\endgroup\$ Oct 3 '17 at 8:47
  • \$\begingroup\$ Yes, except that normally it's not in bit level, but bytes, or actually 'text' characters are read and translated into opcodes. The assembler creates an executable file, which is stored in memory and executed instruction by instruction. \$\endgroup\$ Oct 3 '17 at 8:55
  • \$\begingroup\$ I think "read and translation" is confusing to me because assembler is just replacing certain bits/bytes saved in memory ( ASCII code of English typed texts when we programme) by the bits/btyes (opcodes) which will work in computer. \$\endgroup\$ Oct 3 '17 at 9:05
  • \$\begingroup\$ Actually it does not matter much if it is saved into memory or a file on disk for the translation. I try to add it in my answer \$\endgroup\$ Oct 3 '17 at 9:19
  • \$\begingroup\$ I know that the edit you made in your answer should've cleared all the doubts for a knowing person. But sir I am beginner to computer organization and architecture + programming languages. I don't know parsing ( although I got little feeling about that) also "translation" word confuses me every time .I think I just want to know that what happens in the memory (RAM) from when I start writing something on my "programming software". 1/2 \$\endgroup\$ Oct 5 '17 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.