Reputation: 1089
Are assembly language and machine language (for the same underlying system) really the same? Are there any differences between these two concepts?
Upvotes: 35
Views: 82040
Reputation: 5318
Machine language is the "bit encoding" of a CPU's opcodes.
Assembly language 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 this 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 occasionally 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:
# Mythical CPU macro
.macro spinSleep x,y
ld #x,y
localLoop: dec y
brq localLoop
.endmacro
# Macro invocation
spinSleep 100,R1
# Macro expansion
ld #100,R1
localLoopM: dec R1
brq localLoopM # localLoopM is "mangled" for localization.
Upvotes: 20
Reputation: 173
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]
Upvotes: 3
Reputation: 994
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.
Upvotes: 0
Reputation: 170539
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.
Upvotes: 40
Reputation: 23
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.
Upvotes: 0
Reputation: 1
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.
Upvotes: -3
Reputation: 361702
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?
Upvotes: 7
Reputation: 974
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).
Upvotes: 0
Reputation: 3235
In Assembly, instructions are easier-to-understand representations of CPU instructions.
But the assembler also makes, for example, addressing easier:
This makes assembly much easier to maintain, especially when the distance between the addresses changes.
Upvotes: 5