Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Assembly and binary?

I've trouble with understanding the difference between assembly and binary. Just I need to understand what the relation is between linked binary and assembly.

like image 689
Bousselham Kh Avatar asked Feb 07 '16 17:02

Bousselham Kh


2 Answers

Assembly is basically binary code written in a form that humans can read. The assembler then takes the assembly code and translates it line by line to the corresponding bit code.

Imagine that there is a table with a line for each possible assembly statement. Then on each line there is on the left the statement itself, and on the right the corresponding bits that the computer can understand

That being said assemblers also have extra functionality like macros etc. but the main functionality is that described above.

like image 184
mandragore Avatar answered Oct 21 '22 16:10

mandragore


For programmers, Binary is just a numbering system. For example, base2 consists of some 0's and 1's. All computers work with these binary numbers (0 and 1). They perceive the instructions as a set of these numbers. They do not feel the human-generated code which is generally generated using a high-level programming language such as Python, Java, and etc.

It is obvious that machine instructions in computers are not really human-readable –most people can't figure out the operational difference between 100010001... and 010001000... by just looking at a binary or hex representation of the instruction bytes. These instructions are just Machine Codes.

For instance, the machine code for loading a value into a register in x86-16 architecture takes this instruction as a HEX code: 8B 0E 34 12 where 8B means mov r16, r/m16 and 0E specifies which register the destination is (in this case CX), and which memory/source register with a 2-bit addressing mode field and 3-bit base register (in this specific case, there is no register, just a 16-bit absolute displacement).

P.S. Just to be clear, HEX code is used to represent the Machine Code. Actually, it is easy to translate it to binary "10001011000011100011010000010010" and this is what you have mentioned as binary. HEX is just a text serialization format for binary numbers like a string of ASCII 0 and 1, but more compact.

Assembly is more high-level than Machine Code and makes such binray/HEX instructions readable for human. For example, the machine code 8B 0E 34 12 would be decoded / disassembled to MOV CX, [1234H].

like image 24
inverted_index Avatar answered Oct 21 '22 18:10

inverted_index