BIOS Programming

Welcome

When working with assembly understanding what a byte is, is very helpful. However, before we can get into bytes we need to cover a little number theory with binary and hexadecimal. Let's start with something familiar. The base-10, decimal, number system.

Decimal

In our normal day to day lives we use the base-10 number system, which is called decimal. With the base ten number system we have a symbol to represent numbers zero through nine.

0 is for zero

1 is for one

2 is for two

...

9 is for nine

When we get to the number ten (same as the base), we need to use two symbols (ie: 10).

Hexadecimal

When we looked at decimal there was no one symbol to represent the number ten. Now with hexadecimal, with base sixteen, we have no one symbol for sixteen, we do however need one symbol for all the numbers less than sixteen. Let's look at how we represent this.

0 is for zero

1 is for one

2 is for two

...

9 is for nine

A is for ten

B is for eleven

C is for twelve

D is for thirteen

E is for fourteen

F is for fifteen

Again, when we get to the number sixteen (same as the base), we need to use two symbols (ie: 10).

Binary

This leads us to binary, which is base-2. If we look at the pattern with base-10, there was no one symbol for the number 10. With base-16, there was no one symbol for the number sixteen. With base-2, there is no one symbol to represent two.

0 is for zero.

1 is for one.

Again, when we get to the number two (same as the base), we need to use two symbols (ie: 10). Let's count further.

10 is for two.

11 is for three.

100 is for four.

101 is for five.

etc...

About the Byte

When we look at binary, all numbers can be represented as either a 1 or a 0, which when applied to switches the switch is either turned on or off. Each Binary digIT is called a bit. In a byte there are 8 bits. There are also nybbles, which is only 4 bits.

There is another unique relationship with binary and hexadecimal. Each hexidecimal number represents one nybble. When working with assembly a number in binary is shown with a trailing "b". An example is 01b. With hexadecimal there is a trailing "h" or a "0x" in front. An example is 10h or 0x10. Ok, let's look at some examples of this.

0000b is the same as 0x0

0001b is the same as 0x1

0010b is the same as 0x2

0011b is the same as 0x3

...

1000b is the same as 0x8

1001b is the same as 0x9

1010b is the same as 0xA (which is ten)

When we look at the worst case we have 1111b which is 0xF. As you can see all four bits can represent one hexadecimal digit.

Places

In decimal we multiply and divide by 10 by moving the decimal place. For example 1000 / 10 is 100. This also happens with hexidecimal except that you multiply and divide by 16 and with binary you divide and multiply by 2.