Chapter 1 - Basic Concepts

This course combines assembly language programming with the study of elementary computer architecture. In my opinion, this is the most important fundamental class in all of Computer Science. A firm understanding of this material opens the doors to most other Computer Science classes.

Let's begin by defining each of the following terms:
1) Microprocessor
2) Machine Language
3) Assembly Language
4) High Level Language
5) Assembler
6) Compiler

Positional Number Systems

In order to work effectively in the assembly world, we must be able to work with the following number systems:
1) Decimal
2) Binary
3) Hexadecimal

Decimal Number System

The decimal number system is base 10 and the radix point is referred to as the decimal point. The symbols that make up the decimal number system are the digits: 0,1,2,3,4,5,6,7,8,9 and the decimal point. As an example, let's look at the decimal number 123.45.

123.45 = 1x10^2 + 2x10^1 + 3x10^0 + 4x10^(-1) + 5x10^(-2)
       = 100    + 20     + 3      + .4        + .05

Binary Number System

The binary number system is necessary because digital computers only use 0's and 1's. In particular, the components of digital computers are two-state devices (on/off,0/1, high/low,...).

The binary number system is base 2 and the radix point is referred to as the binary point. The symbols that make up the binary number system are the digits: 0,1 and the binary point. We know that a single binary digit is called a bit.

To convert a binary value to its decimal equivalent we can simply write out the binary number in the same long hand notation that we used for the decimal number and then add up each piece as follows:

1010.01 = 1x2^3 + 0x2^2 + 1x2^1 + 0x2^0 + 0x2^(-1) + 1x2^(-2)
        = 8     + 0     + 2     + 0     + 0        + .25

So (1010.01) base 2 equals (10.25) base 10

Problem: Fill in the table below:

Decimal     Binary
3
4
8
16
9.75

To convert a binary number to decimal is pretty straight forward, but to convert a decimal number to binary is a little more complicated. The number needs to be divided into two pieces: (1) the integer part (2) the fractional part.

Problem: Let's convert the decimal number 23.3125 to binary:

(1) Convert the integer part 23 to binary:

     Integer   Quotient     Remainder
     -------   --------     ---------
     23
     23/2      11           1
     11/2      5            1
     5/2       2            1
     2/2       1            0
     1/2       0            1

So 23 base 10 is 10111 base 2. Notice that you take the bits from the remainder from bottom to top to compose the number.

(2) Convert the decimal part .3125 to binary:

     Fractional      Fractional*2    Bit    Next Fraction
     ----------      ------------    ---    -------------
     .3125           0.6250          0      .6250
     .6250           1.250           1      .250
     .250            0.50            0      .5
     .5              1.0             1      0
In this case you take the bits from top to bottom. So 23.3125 base 10 is equal to 10111.0101 base 2. Cool!!!

Two other number systems are important to us:
1) Octal
2) Hexadecimal

Question#1: What symbols are used in the octal number system?

Question#2: What symbols are used in the hexadecimal(hex) number system?

We should be able to use part of what we learned from the decimal and binary number systems to answer each of the following questions:

Question#3: What is the octal number 11 in decimal?

Question#4: What is the hex number 11 in decimal?

Problem: Consider the decimal number 35. Compute the value of this number in each of the following bases: (a) binary (b) octal (c) hexadecimal. I don't care how you come up with the answer.

We need to find a way to do each of the following conversions:

1) decimal -> binary
2) decimal -> octal
3) decimal -> hex
4) binary -> decimal
5) octal -> decimal
6) hex -> decimal
7) binary -> octal
8) binary -> hex
9) octal -> binary
10) hex -> binary
11) octal -> hex
12) hex -> octal

From our discussion we should now feel comfortable with 1 through 6 above. Any questions on 1 through 6?

7) binary -> octal is pretty neat and interesting. Consider the binary number 101001.01101

What is this value in decimal? octal?

I'll leave the decimal for you but as for the octal, we simply start from the binary point and go left in groups of three bits and do the same from the binary point to the right. Add zeros to the front and back of the number until all groups consist of three bits. So for the above number we must add a zero to the end of the number only (101001.011010). Now we do our groups of three as follows:

101  001  .  011  010   (base 2 or binary)
5    1    .  3    2     (base 8 or octal)

Now you try one.

Problem: Convert 10110101.1100111 binary to octal.

8) binary -> hex is very similar to binary -> octal except you group by fours instead of by threes. Zeros are added to make groups of fours evenly at the front and back of the number.

Let's convert 101001.011010 from binary to hex.

0010  1001  .  0110  1000   (base 2 or binary)
2     9     .  6     8      (base 16 or hex)

Problem: Convert 10110101.1100111 binary to hex.

9) In order to convert from octal -> binary just reverse the process. That is, convert each octal digit to binary using 3 bits.

Problem: Convert the octal number 43.26 to binary.

10) In order to convert from hex -> binary just reverse the process. That is, convert each hex digit to binary using 4 bits.

Problem: Convert the hex number 43.26 to binary. What about fa.c ?

11) To go from octal to hex it's very easy to go through the binary representation and regroup.

Problem: Convert 23.67 octal to hex.

12) Finally to go from hex to octal, go through the binary also.

Problem: Convert ab.72 hex to octal.

Why did we go through all of these exercises? The answer lies in the fact that we as human beings tend to think in terms of the decimal number system. We have grown up with this system and are very used to it; therefore, we need it. The digital computer is strictly zeros and ones. When we examine memory or look at machine code, this is usually represented using hex notation or octal notation. Why?

Hex notation is MUCH more widely used than octal!!


© Douglas J. Ryan/ryandj@pacificu.edu