33

Are assembly language and machine language (for the same underlying system) really the same? Are there any differences between these two concepts?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
freenight
  • 1,069
  • 3
  • 13
  • 19
  • As far as a concept goes assembly language is all about labor saving. From the ideal one to one instruction to mnemonics to additional non-instruction parts of the language. Also related to the word concept, the machine language is defined by the logic and assumed to not be changeable (there are exceptions lets ignore those for now) where assembly language is defined by the assembler, and you can have as many (incompatible) assembly languages as folks care to write for one machine language. You as the user get to pick the one you prefer. This is not limited to x86 BTW. – old_timer Aug 08 '18 at 12:50

9 Answers9

40

Assembly language is a convenience mechanism over the machine language. With assembly language you use mnemonic sequences instead of numeric operation codes and can use symbolic labels instead of manually calculating offsets. It also protects you from really dumb errors - like typing a malformed processor instruction.

Otherwise the assembly language is the equivalent of the machine language. Sometimes you will have an old assembler that will not support mnemonics for some instructions of the newer processors - then you can still insert operation codes directly into the program.

Gareth
  • 2,746
  • 4
  • 30
  • 44
sharptooth
  • 167,383
  • 100
  • 513
  • 979
  • Assembly language is more than just an equivalent, it very often includes additional labor saving devices other than just making the instructions easier to read/write for humans. Labels, directives, sometimes a macro language, etc are all part of the assembly language it is most often not limited to the ideal one to one machine to/from mnemonics. – old_timer Aug 08 '18 at 12:45
19

Machine language is the "Bit encoding" of a CPU's opcodes.

Assembly langauge is the "Symbolic encoding" of a CPU's opcodes.

So for Example Symbolically:

loop:  dec R1    # Decrement register R1
       bnq loop  # Branch if not equal to zero to
                 # address "loop"

Becomes Bit encoding:

# Mythical CPU Machine code 4 bits operation,
#                           4 bit "option"
       0x41      # 4 is a "dec" and represents r1;
       0x7E      # 7 is bnq and E means PC -2;

Generally it's a one to one relationship, however some assembly languages will ocationally have extra assembly instructions that map to either multiple machine code instructions or reuse another opcode. Such as using machine code "xor R1,R1" as a "clr R1" or something very similar.

In addition assembly languages will tend to support "macro programming" which in the 80's when assembly was used extensively gave the source code a more "high level" appearance. I've personally written assembly macros that looked like "plot x,y" and "Hex Val" to simplify common operations.

For example:

# Mythically CPU Macro
.macro spinSleep x,y
            ld #x,y
localLoop:  dec y
            brq localLoop
.endmacro
# Macro invocation
            spinSleep 100,R1
# Macro expantion
            ld #100,R1
localLoopM: dec R1
            brq localLoopM   # localLoopM is "Mangled" for localization.
NoMoreZealots
  • 5,274
  • 7
  • 39
  • 56
7

I found a really good explanation, thought to post it here, so that others could read it:

Machine language is the actual bits used to control the processor in the computer, usually viewed as a sequence of hexadecimal numbers (typically bytes). The processor reads these bits in from program memory, and the bits represent "instructions" as to what to do next. Thus machine language provides a way of entering instructions into a computer (whether through switches, punched tape, or a binary file).

Assembly language is a more human readable view of machine language. Instead of representing the machine language as numbers, the instructions and registers are given names (typically abbreviated words, or mnemonics, eg ld means "load"). Unlike a high level language, assembler is very close to the machine language. The main abstractions (apart from the mnemonics) are the use of labels instead of fixed memory addresses, and comments.

An assembly language program (ie a text file) is translated to machine language by an assembler. A disassembler performs the reverse function (although the comments and the names of labels will have been discarded in the assembler process).

Source : What is difference between machine language and assembly language?

Nawaz
  • 353,942
  • 115
  • 666
  • 851
5

In Assembly, instructions are easier-to-understand representations of CPU instructions.

But the assembler also makes, for example, addressing easier:

  • In machine language you have to know the distance (in address space) between where you are and where you want to jump to
  • In Assembly language you call one address "iWantToJumpHere" and then you can say "jump iWantToJumpHere"

This makes assembly much easier to maintain, especially when the distance between the addresses changes.

weiqure
  • 3,247
  • 2
  • 27
  • 31
2

machine language is what the chip understands Assembly is what you understand

Every assembly instruction has a machine language equivalent. x86 has a few single-byte instructions, but they're variable length and can be up to 15 bytes long (including optional prefixes)

 machine code bytes |   x86 assembly language
8D B0 00 36 65 C4    lea    esi, [eax - 1000000000]     
BB 00 FC FF FF       mov    ebx, -1024
43                   inc    ebx
41                   inc    eax
3B CA                cmp    ecx,edx
C3                   ret

C5 F5 72 D2 01       vpsrld ymm1,ymm2,0x1        ; AVX2
C5 F5 D4 6D 88       vpaddq ymm5,ymm1,YMMWORD PTR [ebp-0x78]
C5 CD D4 AD 68 ff ff ff vpaddq ymm5,ymm6,YMMWORD PTR [ebp-0x98]
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
ady
  • 155
  • 1
  • 8
0

Assemble level language is the first conscious step towards making the programming simple by allowing the programmers to write mnemonics instead of binary code(machine code).

Pranali Desai
  • 974
  • 1
  • 7
  • 22
0

Assembly language is first converted to machine language by the assembler. which is stored in memory (RAM) processor/cup fetch it and store in from memory to register and follow the instruction set one after one.

  • 2
    Correct up to the point where you say an instruction is stored in a register. This is *not* necessarily the case; CISC machines like x86 or VAX have variable-length instructions and can't usefully use the bits of an instruction as internal control signals the way an in-order non-superscalar MIPS can. [x86 registers: MBR/MDR and instruction registers](https://stackoverflow.com/q/51522368). Even out-of-order CPUs give the illusion of running instructions one after another, though, so that's a useful description. Except for VLIW architectures with explicit parallelism! – Peter Cordes Aug 05 '18 at 18:51
0

Machine Language

Machine language consists of ones and zeros. so it's so hard to understand by looking at it. so if we want to modify the code , it will be a huge problem. Machine languages is also a programming language(1st Gen).our computer CPU can directly execute that machine code without any assembler.

Assembly Language

assembly language consists of syntax , number , and letter. it's easy to modify existing code. so our machine cannot understand that program. so machine using an assembler to convert that assembly language code into machine code.

Malith Ileperuma
  • 926
  • 11
  • 27
-3

Assembly Language is the symbolic encode of opcode (operation code) that is understand by humans and only use to instruct computer processor (hardware operation) and robot (robotic operation) to perform specific tasks. This is an understandable language to human. This language is only use to instruct hardware operation and definitely not use to create software programme. A assembler is use to convert this symbolic encode part of opcode (operation code) into machine language. Operation Code (Opcode) is a part of machine language.

SK4R1M
  • 1