Machine code (using hexadecimal)
Machine code is the term used to describe binary instructions, e.g 0101101010101010010010100111111
Any low-level or high-level language instruction will ultimately end up as a binary instruction.
However, machine code can be represented by the use of hexadecimal code as a low-level language.
Hexadecimal code is the lowest form of programming language used by programmers. It cannot be understood by the processor but it makes binary more readable for humans. It is changed to binary for the processor to understand.
Earlier, we saw how 180 can be converted to binary as 10110100
Using hexadecimal the same instruction can be represented as B4
In hexadecimal the letter B represents the number 11. Hexadecimal code works to the power of 16 (Base 16). The hexadecimal representation of 180 is B4:
This means we are using 16 eleven times (as B represents 11) and we are using 1 four times.
16 x 11 = 176
1 x 4 = 4
176 + 4 = 180
We can see that B4 is a more succinct way of representing 180 than 10110100. Programming in hexadecimal saves time when compared to using binary instructions.
Here are the values 1-26 represented in decimal, binary and hexadecimal.
Decimal
|
Binary
|
Hexadecimal
|
0
|
00000000
|
00
|
1
|
00000001
|
01
|
2
|
00000010
|
02
|
3
|
00000011
|
03
|
4
|
00000100
|
04
|
5
|
00000101
|
05
|
6
|
00000110
|
06
|
7
|
00000111
|
07
|
8
|
00001000
|
08
|
9
|
00001001
|
09
|
10
|
00001010
|
0A
|
11
|
00001011
|
0B
|
12
|
00001100
|
0C
|
13
|
00001101
|
0D
|
14
|
00001110
|
0E
|
15
|
00001111
|
0F
|
16
|
00010000
|
10
|
17
|
0010001
|
11
|
18
|
00010010
|
12
|
19
|
00010011
|
13
|
20
|
00010100
|
14
|
21
|
00010101
|
15
|
22
|
00010110
|
16
|
23
|
00010111
|
17
|
24
|
00011000
|
18
|
25
|
00011001
|
19
|
26
|
00011010
|
1A
|
Here we can see an example of the value for 500 in both binary and hexadecimal:
Binary
256
|
128
|
64
|
32
|
16
|
8
|
4
|
2
|
1
|
1
|
1
|
1
|
1
|
1
|
0
|
1
|
0
|
0
|
256 + 128 + 64 + 32 + 16 + 4 = 500
Hexadecimal
F represents 15 in hexadecimal so...
(256 x 1) + (16 x 15) + (1 x 4) = 500
An example of a complete binary instruction and the same hexadecimal instruction is shown below:
10110100 00000000 10110000 00010011 11001101 00010000
B4 00 B0 13 CD 10
Hexadecimal values are used to write instructions that are easier for humans to work with than machine code.
Assembly code
Assembly code is another form of low-level language. Assembly code is created by the developers of processors. Assembly languages are architecture dependent - the form of assembly code depends upon the manufacturer of the processor.
Like hexadecimal code, assembly code does need some form of alteration before it can be understood by the processor. An assembler is the name given to the software that converts assembly code into binary instructions.
Assemblers generally allow for one to one conversion between an assembly language instruction and binary code. Assembly language is often used when high performance is crucial. The main drawbacks of assembly languages are lack of portability and the time that it takes to learn how to program.
Here is the same instruction three times, once in binary, once using hexadecimal notation and once using an assembly language.
Binary instruction
|
Hexadecimal machine code
|
Assembly code
|
101101000000000010110000000100111100110100010000
|
B4 00 B0 13 CD 10
|
mov ah, 0 / mov al, 13h / int 10
|
Share with your friends: |