Assembly Tutorial

Hexadecimal notation is a base-16 number system that uses the digits 0-9 and the letters A-F to represent numbers. It is a more compact and easier-to-read format than binary notation, which is why it is often used in assembly language programming.

## Converting Between Hexadecimal and Decimal

To convert a hexadecimal number to decimal, simply multiply each digit by its corresponding power of 16 and add the results together. For example, to convert the hexadecimal number 1010h to decimal, we would do the following:

1010h = 1 * 16^ 3 + 0 * 16^ 2 + 1 * 16^ 1 + 0 * 16^ 0 = 4096 + 16 + 0 = 4112

To convert a decimal number to hexadecimal, we can use the following algorithm:

1. Divide the decimal number by 16 and get the quotient and remainder.
2. The remainder is the least significant digit of the hexadecimal number.
3. Repeat steps 1 and 2 until the quotient is 0.
4. The hexadecimal number is formed by writing the remainders in reverse order.

For example, to convert the decimal number 4112 to hexadecimal, we would do the following:

4112 / 16 = 257 and 0 (remainder) 257 / 16 = 16 and 1 (remainder) 16 / 16 = 1 and 0 (remainder) 1 / 16 = 0 and 1 (remainder) Hexadecimal number = 1010h

## Using Hexadecimal Notation in Assembly Language

Assembly language programmers can use hexadecimal notation to represent data and instructions in a more compact and easier-to-read format. For example, the following assembly language instruction stores the hexadecimal value 1010h in the register EAX:

mov eax, 1010h

This instruction is equivalent to the following assembly language instruction, which stores the decimal value 4112 in the register EAX:

mov eax, 4112

Hexadecimal notation can also be used to represent addresses in memory. For example, the following assembly language instruction jumps to the address stored in the register EDI:

jmp edi

Hexadecimal simplifies binary representation by grouping 4 bits into a single hexadecimal digit.

; Binary representation of the decimal number 10 1010 ; Hexadecimal representation: A

Hexadecimal numbers are commonly used in registers for clarity and compactness.

Memory addresses are often represented in hexadecimal to indicate the location of data in memory.