The above image shows the motherboard of the Commodore 64, contained within the motherboard are circuits. These circuits are designed to have two states : on and off. These states are represented with different electronic voltage levels. This is why we say that all data or information which flows through a computer is a stream of zero’s and ones. The zero’s represent circuits which are off (or at low voltage) and the one’s represent circuits which are on(or at high voltage).
These streams of ones and zeros are called machine code and attempting to code or reach these lines is incredibly unwieldy and error prone for humans.
To help us to create great programs we represent these numbers in different ways. This helps humans understand what is happening on the circuit board and how to control the flow of information. This information is then converted to machine code as a final stage before the program is run.
As a primer to understand Assembly Language and how to code in it, lets examine the different methods of counting. Trust me, it becomes relevant later.
Bases – how to count
From our early school days we are familiar with the base ten or decimal number system. It’s called base ten due to the fact that there are ten individual numbers or digits: 0 to 9. To count past 9 we reuse those same digits i.e. 10,11,12 etc. The reasons we are more comfortable using this system are historic and most likely relate to us having ten fingers (including thumbs) to count with.
Looking at the above graphical example, we can see that each individual digit takes on a specific value with the digits to the right being the lowest amount, increasing in value as we move to the left. These value amounts are the base number value (i.e. 10 for decimal) raised to a power, starting at the power 0 for the rightmost digit and increasing as we move left.
Using the above example, the decimal number 1107, we see that there is 1×1000+1×100+0x10+7×1 = 1107 decimal.
Understanding the examples from the familiar base 10 system, we can look at other number bases as they tend to work in the same way. Binary is one of the most famous bases when we look at computer science and is base two. These denote the circuits we discussed earlier and contain two individual digits 0 and 1.
To count past 1 we reuse those same digits.
Using the above example, the binary number 1011, we see that there is 1×8+0x4+1×2,1×1= 11 decimal.
The most important base to understand for Assembly Language purposes is base 16 or Hexadecimal. These contain sixteen individual digits 0 through 9 and as we then have no further digits to use, it then uses the letters A to F.
To count past 9 we move to the letter A, then B etc until we reach F.
Using the example of the hexadecimal number 10AC, we can see there is 1×4096+0x256+A(translates as 10 in decimal)x16+C(translates as 12 in decimal)x 1. This makes up the value of 4268 in decimal.