SCU Logo

DP234

TOPIC 1
Basic Computer Design

Unit Introduction
References
Topics
   Topic 1 - Basic Computer Design

   Topic 2 - Accessing Memory
   Topic 3 - More Instructions
   Topic 4 - Processes & Interrupts
   Topic 5 - Input & Output
   Topic 6 - Memory
   Topic 7 - Memory Management 1
   Topic 8 - Memory Management 2
   Topic 9- File Systems
   
Topic 10 - Advanced CPU design
L
aboratories
   Lab 1 - Unix commands
   Lab 2 - Data
   Lab 3 - Data & Stack Instructions
   Lab 4 - Arithmetic and Logical Inst.
   Lab 5 - Jumps and Loops
   Lab 6 - Operating System Calls
   Lab 7 - Interrupt Service Routines
   Lab 8 - FAT File Systems
   Lab 9 - Practice Exam
SPASM
  download
  manual


Introduction

This topic will revise basic computer design and computer numbering systems. Both these subtopics will be revision of materials that you may have covered in other units in this course. Basic computer operation was examined in the Introduction to Information Technology unit (DP221) and the computer oriented number systems were or will be covered in detail in Discrete Mathematics (MA213).

In our introduction to computer design we will briefly point out the four main components of a computer system. We will look at the CPU and some of the main components inside it. We will look at the function of memory and the I/O subsystem. In addition, we will see how a computer's bus connects each of the other components together.

We will also discuss computer numbering systems, in particular the binary and hexadecimal number systems. These will be used extensively throughout the practical component of this unit. You will see that these underlying numbering systems also reflect the basic data types in C and C++ languages that you will learn in other units in your course.

You will learn how to convert between binary, hexadecimal and decimal numbers. The representation of negative numbers will also be studied. An alternative to interpretation of binary values as numbers is to interpret them using codes. We will look at ASCII and other codes for interpreting binary values as language symbols.

Finally we will look at the byte representation of large binary values in byte addressable memory.

Objectives

On completion of this topic, you should be able to:

  • describe the basic components of a computer system
    • describe the internal components of the CPU
    • describe the function of memory and the I/O subsystem
  • do conversions between binary, hexadecimal and decimal numbers
  • convert signed binary numbers to their decimal equivalents
    • convert decimal numbers to and from 1's complement numbers
    • convert decimal numbers to and from 2's complement numbers
  • describe and use codes
    • convert binary representations to and from ASCII and other codes
  • show how large binary objects may be stored in big-endian and little-endian format.

Basic microcomputer design

Before we start looking at computer architecture in detail we will revise the main components of a computer system and the basic fetch-execute cycle.

Figure 1.1 shows the major components of a computer system. These are the:

  • Central Processing Unit (CPU). This is the "brains" of the computer. It controls the other components by deciding what to do next.
  • Memory. This is the part of the program that temporarily stores data and instruction for the CPU.
  • I/O Subsystem. This is the part of the computer that interacts with the outside world. If a computer did not have an I/O system then it would not be useful for anything.
  • Bus. This is the "wires" that connect the other three parts of the computer together. Buses are collections of wires that are individually either on or off (0 or 1). Everything connected to the bus sees the same status for each wire.

Now that we have seen the basic components of the system we need to revise how they interact. Figure 1.2 shows the basic fetch-execute cycle of a computer system.

You will see in the remainder of this unit that this basic cycle, with a small variation, is the complete description of the activity of a CPU.

The following textbook reading revises these concepts in more detail. It relates each of the components to real computers. It also covers operating system concepts that we will study later in the unit.


Textbook: Englander, 1996, Section 1.2, pages 11-17.

Activity 1.1: This reading relates to real computer systems. Write down the specifications of your own computer system under the headings of CPU, Memory, I/O Subsystem and Buses.  [Feedback]


We will now revise each of the components of a computer in more detail.

The CPU

In most modern computer systems the CPU is a single chip. In this unit we will also look inside the chip to study internal components. Figure 1.3 shows some of the main components of most CPUs.

In Figure 1.3 several internal components are shown:

  • Registers are temporary storage areas that retain their information between instructions. They usually hold 16, 32 or 64 bits of information.
  • The control unit is the unit responsible for directing the other units inside the CPU. It usually interprets instructions after they have been loaded.
  • The Arithmetic Logic Unit (ALU) performs arithmetic and logic operations on values in the internal registers. It performs operations such as addition, multiplications, logical AND, etc.
  • The interface unit provides the external interface to the CPU. It performs the necessary operations to access memory and the I/O subsystem.
  • Most CPUs also have one or more internal bus to connect the CPU's internal components. It is usually quite different to the computer's main bus as it is designed to work much faster.



Memory

The computer's main memory is used for storing instructions and data. In most modern computers this memory is volatile which means that it looses its memory when the power is removed. This means that main memory is not permanent storage and permanent data must be saved to a permanent medium such as disk or tape. In addition, main memory is usually a scarce resource so many schemes have been invented to make better use of the main memory available. Later in this unit we will study these schemes in more detail.

Memory is divided into many identical storage cells. Each of them contain a fixed number of bits. Most modern computers have eight bit cells which are also called bytes. Each storage cell is given a unique address, which is also called the cell's location. Addresses start at zero and sequentially number each cell.

It is important to note that a CPU only has two ways to access a memory location. It may read a location by transferring a copy of the cell to the CPU. Alternatively, it may write to a memory location. A write operation transfers a new bit pattern to the memory location overwriting its previous contents.

I/O Subsystems

The I/O Subsystem provides a consistent link to the many I/O devices attached to the computer system. The CPU must be able to access each device by a consistent interface.

A CPU accesses devices via I/O ports. These are similar to internal registers or memory cells as they can be used to read information from a device or for the CPU to write data to the device. In this way the CPU can perform input and output to a device.

There are two computer design techniques used for accessing I/O ports:

  • Access the port as a memory address. CPUs that implement this technique reserve a special range of memory addresses for I/O ports. This means that an instruction can access the port using the same instructions that access memory. Motorola 680x0 processors use this technique.
  • Use a separate addressing mechanism. CPUs that reserve a separate address space for I/O ports must use special instructions for accessing the ports. Intel 80x86 processors use this technique.

A characteristic of I/O ports is that they do not always remember the data that is written to them. This is because the attached I/O devices may modify the ports independently from the CPU. This is useful for programs that want to check if an I/O operation has completed (e.g., a mouse click has occurred). Such a program can check the I/O port periodically to check if the port has changed.

You will expand your knowledge of the fourth component (buses) in Topic 2. In the next section we will look at numbering systems. It will be important to develop skills in computer oriented number systems so you can fluently discuss the internal operation of memory, the CPU and I/O modules.

Numbering Systems

To allow us to talk fluently about low level computer concepts we need to use appropriate systems to describe the contents of registers, memory, I/O ports, etc. In this section we will look at binary and hexadecimal numbers which are the main numbering systems for use with low level computers. Techniques for converting these numbers to our familiar decimal counting system will be studied. We will also look at how we can represent negative numbers in computers and how they can be manipulated. Codes are also another technique to allow us to easily interpret the contents of register and memory so we will briefly look at the ASCII code. Finally we will discuss how we can store numbers with more that eight bits in a machine that had eight bit addressable storage cells.

Binary and hexadecimal numbers

As you know from previous units, computers store everything in 1's and 0's. If we want to exactly describe what the contents of a memory cell or a register then we would have to write the complete number of bits. For example, if the number 3 was stored in a byte in memory then the exact contents of the byte could be described as:

0 0 0 0 0 1 1

If a 32-bit register contained the decimal number 234,567 then the exact contents of the register would be (don't worry about the conversion):

0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 0 1 0 0 0 1 1 1

You can probably see that working with binary numbers soon becomes very verbose and prone to error. For this reason, people who frequently work with low level computer architecture use hexadecimal numbers as shorthand. Hexadecimal numbers (hex for short) directly represent binary numbers by assigning a digit to each group of four binary digits.

The following table shows the hex digits for each possible combination of four binary digits. Notice that the first 10 digits correspond to the normal decimal system that you are used to. The remaining 6 had to be taken from somewhere so the letters 'A' to 'F' have been chosen.

binary
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
hex
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F

Hex allows us to exactly represent a byte with two hex digits, a 16-bit value with four hex digits and a 32 bit value with eight hex digits. This is much more compact than a binary representation.

So for example, the above two binary numbers can be represented in hex as:

03 and 0039447

If you examine these numbers by themselves you will have an interpretation problem. Is the number 23 a decimal or a hexadecimal number? In the above context it is obvious which is which. However, this will not always be the case. We will follow the C/C++ convention of writing hex numbers with a preceding '0x' or '0X' string. For example, the above two numbers will be written as:

0x03 and 0x0039447

The same problem arrises when we write binary numbers. Does 10 represent a binary number or the usual decimal ten? To distinguish binary numbers we will precede the number with the string '0b' or '0B'. For example, the binary number 10 will be written as:

0b10

We will use both these conventions for all binary and hex numbers that appear from now on in the unit materials. In the case where the context is clear we will omit these prefixes.

The following textbook reading describes hexadecimal and binary numbers and how to work out the decimal equivalents. Although it is easier to use a calculator you are required to learn the manual procedures. You will find with practice that it is quicker to convert small numbers manually.


Textbook: Englander, 1996, Section 2.0-2.2, pages 30-36.
                       
Englander, 1996, Section 2.6, pages 44-46.

Activity 1.2: For this activity you should work out the answers manually.

  1. What is the hexadecimal equivalent of the following binary numbers?

    0b11111   0b100110   0b101010101010
    0b101100000001


  2. What is the binary equivalent of the following hex numbers?

    0xFF   0x101   0x123   0x100A   0xABCD

  3. What is the decimal and hexadecimal equivalent of the following binary numbers?

    0b111    0b1000    0b11111111
    0b101010101        0b1000000000000000


  4. What is the decimal and binary equivalent of the following hexadecimal numbers?

    0xA    0xA0    0x1A    0xFFFF    0x1000

 [Feedback]


The last reading discussed how to find the decimal equivalents of binary and hex numbers. We also have to convert in the other direction. That is, we need to convert from decimal to binary and from decimal to hexadecimal numbers. The following reading shows you two ways to do this. You should concentrate on the second method and use it in the activities given below.


Textbook: Englander, 1996, Section 2.4, pages 40-43.

Activity 1.3:  For this activity you should work out the answers without a calculator. If you have difficulty with the first one then check you answer in this topic's feedback section before attempting the remainder.

What is the binary and hexadecimal equivalent of the following decimal numbers?

3   255   1234   100   2049

[Feedback]


We have concentrated in this section on the conversion of numbers between three bases (binary, decimal and hexadecimal). You may have noticed in the textbook readings that there is also a lot to learn about arithmetic in the various bases. However, for the purposes of this unit you do not need to know how to do this. When arithmetic arises we can always convert hex and binary numbers to decimal and do the arithmetic. If the answer is required in the other base then we convert the decimal answer to the base.

There is one further attribute of computer numbers that we have not discussed. That is how to represent negative numbers. Representing negative numbers is discussed in the next section.

Representing signed numbers

So far in this topic we have dealt only with positive numbers. You will be aware that most computer languages have an integer data type that allows programs to store negative as well as positive numbers. These can generally be called signed numbers. So how are these stored in memory and registers?

There are two techniques commonly used to store negative numbers. Early computer systems used a technique called 1's complement. Modern computer systems use a technique called 2's complement. We will examine both these techniques. The 2's complement technique will be the one used through the remainder of this unit.

1's complement

1's complement stores a negative number as the complement (logical NOT) of the positive number. For example, the numbers -2 to +2 are stored in 16 bit registers as:

number
binary hex
2
0000 0000 0000 0010 0x0002
1
0000 0000 0000 0001 0x0001
0
0000 0000 0000 0000 0x0000
-1
1111 1111 1111 1110 0xFFFE
-2
1111 1111 1111 1101 0xFFFD

Notice that this technique results in the most significant bit (MSB) being a 1 for negative numbers and a 0 for positive numbers. Another attribute of this system is that the value with all 1 bits (i.e. 0xFFFF in this case) does not have a positive equivalent in the normal number system. It is commonly called negative zero since its complement is zero.

The following reading describes 1's complement in a round about way. It shows why this technique was chosen by describing how addition and subtraction are done. The text shows how the system would work using a decimal number equivalent. While reading this you should remember that it's the binary 1's complement that we are studying.


Textbook: Englander, 1996, Section 4.4, pages 97-104.

Activity 1.4:  For this activity you should work out the answers manually.

  1. What is the 1's complement binary and hexadecimal equivalent of the following decimal numbers? Assume 16-bit representation.

    23 -3 -255 -1234 2.

  2. What is the decimal equivalent of the following 16-bit 1's complement numbers?

    0xF 0xFFFF 0xFFF7 0xFFF0

[Feedback]



2's compliment

2's complement stores a negative number as the complement (logical NOT) of the positive number plus one. For example, the numbers -2 to +2 are stored in 16 bit registers as:

number
binary hex
2
0000 0000 0000 0010 0x0002
1
0000 0000 0000 0001 0x0001
0
0000 0000 0000 0000 0x0000
-1
1111 1111 1111 1111 0xFFFF
-2
1111 1111 1111 1110 0xFFFE

Notice that this technique again results in the most significant bit (MSB) being a 1 for negative numbers and a 0 for positive numbers. This system also eliminates the redundant negative zero value so it can represent one more signed value than 1's complement.

The following reading describes 2's complement in the same round about way as the text described 1's complement. It shows why this technique was chosen by describing how addition and subtraction are done. The text shows how the system would work using a decimal number equivalent. While reading this you should remember that its the binary 2's complement that we are studying.


Textbook: Englander, 1996, Section 4.4, pages 104-107.

Activity 1.5:  For this activity you should work out the answers manually.

  1. What is the 2's complement binary and hexadecimal equivalent of the following decimal numbers? Assume 16-bit representation and compare your answers to Activity 1.4.

    23   -3   -255   -1234

  2. What is the decimal equivalent of the following 16-bit 2's complement numbers?

    0xF   0xFFFF   0xFFF7   0xFFF0

[Feedback]


In this section we have examined the representation of integers in computer systems. There are several things we have skipped over or avoided. We have not examined closely how arithmetic is done in binary and hex numbers. In general this is not important for this unit. If you wish to check the results of computer arithmetic in the practical part of this unit then you must either use a calculator or convert numbers to decimal equivalents and then do decimal arithmetic.

A large area we have not mentioned at all is how to represent fractions in the computer. We will briefly look at this problem in a later topic where will see how floating point numbers are represented. We will not look at these at all in the practical part of this unit.

Next, we will examine another way to look at the contents of memory cells and registers. Instead of interpreting them as numbers we can interpret them as codes.

Codes

Another way of interpreting binary numbers is by assigning a property to each bit pattern. Looking at this another way, we can assign a bit pattern or code to a number of properties.

In this section we will look at assigning codes to symbols of an alphabet. We can assign a certain binary code for each symbol so that whenever this code appears it can be interpreted as that symbol. We can also develop input and output devices which reproduce the symbol whenever they are presented with the bit pattern through an I/O port.

The most common of these codes at the present time is ASCII (American Standard Code for Information Interchange). It is a 7 bit code that represents 96 printable characters and 32 control characters. Figure 1.4 shows a table of ASCII codes.

To find the code for one of the ASCII symbols we read the first three bits from the top of the table and the next four bits from the left-hand side. For example, the letter capital C ( 'C') has binary code 1000011.

ASCII is not the only code available. EBCDIC (Extended Binary Coded Decimal Interchange Code) is used extensively by IBM mainframe equipment. A new 16-bit code called Unicode is also gaining acceptance by users of the Internet. Because of the large number of codes possible, symbols from many languages can be included in Unicode.


Textbook: Englander, 1996, Section 3.0-3.2, pages 59-69.

Activity 1.6:

  1. How is the string "Catch 22" stored in ASCII?

  2. How is the string "Catch 22" stored in EBCDIC?

  3. What English phrase is stored as the following ASCII hex code?

    48 65 6C 6C 6F 20 77 6F 72 6C 64 21

[Feedback]


You will also notice from the above reading that codes can be used to store useful things besides language symbols. We will not study these in this unit.

Finally, we now look at how we can store large binary objects (numbers, codes, etc.) in memory that is normally organised as addressable 8-bit units.

Storing large binary objects

An interesting question arises when we wish to store multi-byte objects in byte addressable storage. For example, suppose we have the 32-bit number value 0x12345678. This must be stored in four bytes in memory, so let's suppose they are addresses 0x400, 0x401, 0x402 and 0x403. There are two possibilities:

address
option1
option2
0x400
12
78
0x401
34
56
0x402
56
34
0x403
78
12

At first glance the first of these methods appears the most obvious way to store numbers. It stores the big end of the number first and is called big-endian byte order. It means that the address of the 32-bit number is the address of the most significant byte. However, the second techniques which stores the little end first (little-endian byte order) is also used. For example, all Intel 80x86 processors are little-endian. This technique has the advantage that bytes are stored in the same order as bits so that the least significant bits have the lowest memory address.

There has been considerable debate about which ordering is more appropriate. In fact the names little-endian and big-endian reflect the non-agreement of computer system designers. These terms are taken from Jonathon Swift's novel Gulliver's Travels where a religious war broke out between two sides who broke their eggs at the big end (big-endians) and those who broke their eggs at the little end (little-endians). The issue is similarly unresolved.

In general, the byte order is not noticeable in a program. You will need to understand the byte order when examining dumps of memory, which display large binary numbers as separate bytes. However, the main difficulty with the alternate approaches is when data is transferred between machines with different architectures. Any data unit greater than one byte long will have its byte ordering reversed so a conversion will have to be made.


Activity 1.7: Suppose memory at addresses 0x400, 0x401, 0x402 and 0x403 respectively contained the hex value 45, 56, 67 and 01. What is the 32-bit number stored at address 0x400 in a big-endian computer system? What if it is a little-endian computer? [Feedback]



Summary

In this topic we have revised the basic operation of a computer system. We briefly examined each of the four main components, ie. the CPU, memory, I/O subsystem and the bus that connects the other three parts together.

We also looked at how numbers and codes are handled inside the computer. Hexadecimal and binary representations were discussed, as was how to convert binary and hex to decimal numbers and vice versa. The 1's complement and 2's complement techniques for representing signed numbers were also examined. Finally we saw that there were two alternate methods of storing large binary numbers in memory.

In the next topic we will look more closely at memory and how the CPU accesses it. We will start to examine the SPASM machine by looking at some of its instructions.


This page maintained by Barry Wilks.  (updated November, 1999)
© Southern Cross University, 1999