CSE 111, Fall 2000

Great Ideas in Computer Science

Lecture Notes #31

MACHINE ARCHITECTURE
AND ASSEMBLY LANGUAGE

(3.  Assembly Language Programming (continued))


d)    For a full list of P88 Assembly Language
       instructions, click here.

e)    Here's another example, a program to add
       2 integers:

        IN AX
        COPY M, AX
        IN AX
        ADD AX, M
        OUT AX
        HALT

f)      This corresponds to the following Pascal
        program instructions:

        readln(AX);
        M := AX;
        readln(AX);
        AX := AX + M;
        writeln(AX)

g)    And here's how it is executed:

        First, let's suppose that the instructions are
        stored in memory at addresses 0..5:

        0.    IN AX
        1.    COPY M, AX
        ...
        5.    HALT

        The IP is initialized to point to 0
        (we can assume that the compiler does this
        for us).

        So instruction 0 is copied into the IR,
        the IP is incremented to 1,
        and the instruction in the IR is executed:

            An integer is read into the AX
            (say, 4, as in lecture today)

        Next, the instruction in IP is found, and is
        copied into the IR; IP is incremented,
        and instruction 1 is executed:

            the 4 in AX is copied into a memory
            location named "M"

        Next, instruction 2 is found & copied into IR;
        IP is incremented, and IR is executed:

            Another integer (say, 5) is input to AX

        Next, instruction 3 is copied into IR
        & IP is incremented; IR is executed:

            The contents of M (namely, 4) are
            added to the contents of AX (namely, 5),
            to yield 9, and 9 is stored in AX.

        Next, instruction 4 is copied into IR,
        IP is incremented, and IR is executed:

            The contents of AX (namely, 9) are
            written out to the computer's output
            device.

        Next, instruction 5 (= HALT) is copied
        into IR, IP is incremented to 6 (which
        is not the address of any instruction),
        and IR is executed:

            IR is executed by changing IP to -1

        (NOTE:  I HAVE MODIFIED THE SEMANTICS
        FOR "HALT" FROM WHAT I HANDED OUT IN
        LECTURE, IN ORDER TO MAKE IT CONSISTENT
        WITH THE "COMPWORKS" PROGRAMS)

        Since there is no instruction in address -1,
        the fetch-execute cycle is over.

h)    Here's a table of the sort you'll be asked to
        construct for HW #12 that records the above
        execution procedure:

        instruction    AX    M    output
        =========    ==    ==    =====
        0                    4
        1                    4      4
        2                    5      4
        3                    9      4
        4                    9      4        9
        5                    (program halts)
 

4.    Compworks program

a)    For dynamic demos of this, download the
        "compworks" programs from the Great
        Ideas text's website.

b)    Click here for instructions on how to do this.


Copyright © 2000 by William J. Rapaport (rapaport@cse.buffalo.edu)

file: 111F00/lecturenotes31.27nv00.html