Lecture Notes 08 (7 February 2002)

Assembly Language Programming


Please Note:

  • Today's lecture will involve many demonstrations using the "PIPPIN" software from the DH text. Please see the following information regarding using the Decker/Hirschfield software.

  • Overall Reading
    Decker/Hirshfield: pp. 207-214; Mod. 7.4

    Outline:

  • Overview
  • Machine Language vs. Assembly Language
  • Examples

  • Overview

    This lecture is really a continuation of the previous lecture. In that lecture we examined the hardware which makes up a computer system, paying particular attention to the design of the Central Processing Unit (CPU).

    This lecture will switch the focus towards a more careful examination of the software which controls the operation of the CPU. To make these issues concrete, we will use a particular set of CPU instructions called "PIPPIN" from the Decker/Hirschfield text.

    Our goals are twofold:

  • At first, we would like you to understand the "fetch-decode-execute" cycle of the CPU well enough so that you will be able to simulate the execution of a PIPPIN program that has been written by someone else.

  • Secondly, we would like you to understand the PIPPIN instruction set well enough that you can write your own programs, accomplishing some simple tasks.

  • Machine Language vs. Assembly Language

    Machines only deal with 0's and 1's. All of the data must be represented in this way. Furthermore, each type of instructions is encoded using a pattern of bits known as an "op code."

    Here is a snapshot from the PIPPIN simulator.

    Though humans can learn to process 0's and 1's, it certainly is not the most comfortable. We recogize numbers in base 10 more easily and when programming a CPU, we prefer our instructions to have more meaningful identifiers, such as "HLT" rather than "00001111."

    Here is the identical PIPPIN configuration, shown in symbolic mode:

  • In spirit, program instructions and data are stored in the same way in memory. However the simulator differentiates them when running in Symbolic mode.

    The top half of the RAM is used for storing the program instructions. Even in symbolic mode, the memory address are numeric.

    The bottom half of the RAM is used for storing data. Though real computer programs would rely on significant data storage, the simulator only allows for eight bytes of data. Also, rather than reference them numerically, when in symbolic mode they have given those eight memory cells the identities: {W, X, Y, Z, T1, T2, T3, T4}. This is traditionally the way that registers are handled by some CPUs.

    In most of the sample programs we will look at, the first four of those are often used to represent input or resulting output, and the other four are generally used as "temporary" storage along the way, hence the names T1, T2, T3, T4.

  • The relationship between op codes and instruction mnemonics is given in the User's Guide for PIPPIN on page 260 of [DH]. Let's review the instruction set.

  • Examples

    The rest of this lecture will be devoted to looking at program examples.

  • Machine Language
    To demonstrate the advantage of using assembly language, lets start by looking at a program represented directly in machine language. [download PIPPIN file]

  • Assembly Language
    Let's try to write our own programs.
  • Set W = X+Y-Z
  • Set W = (3*X)-Y
  • Set W = 3*(X-Y)

  • Example 1 from p. 211 of [DH]
    [download PIPPIN file]

    What's new in this example is the use of the CPL instruction.


  • An "If" Statment
    When describing an algorithm, there are times when an instruction should only be done when a certain condition is met. For example, let's look at a program for computing the "absolute value" of the value X.

     if (X is not greater than or equal to zero) then
        Multiply X by -1
    

    Here is one PIPPIN solution. [download PIPPIN file]

    And here is an alternate solution. [download PIPPIN file]


  • Example 2 from pp. 212-213 of [DH]
    [download PIPPIN file]

    This program is used to sum the numbers 1+2+...+Z, for some initial value of Z assumed to be non-negative. Doing this requires use of a loop. We might express the algorithm as follows:

    Note: We will use X to count from 1 to Z
          We will use Y to keep a running tally of the sum
    
    Set X = 1.
    Set Y = 0.
    while (X is less than or equal to Z) do
      Set Y <- (X+Y)
      Set X <- (X+1)
    

  • comp150 Class Page
    mhg@cs.luc.edu
    Last modified: 5 February 2002