Information Technology Reference
In-Depth Information
The jump instruction will make the processor jump to the memory address associ-
ated with the label START, thus executing the instruction LD X immediately
after the BRA instruction.
In addition to program instructions, an assembly program may also include
pseudo instructions or assembler directives. Assembler directives are commands
that are understood by the assembler and do not correspond to actual machine
instructions. For example, the assembler can be asked to allocate memory storage.
In our assembly language for the simple processor, we assume that we can use
the pseudo instruction W to reserve a word (16 bits) in memory. For example,
the following pseudo instruction reserves a word for the label X and initializing
it to the decimal value 350:
X
W
350
\ reserve a word initialized to 350
Again, the label of the pseudo instruction W 350 is X, which means it is the memory
address of this value. The following is the assembly code of the machine language
program of Example 1 in the previous section.
LD X
\ AC X
MOVAC
\ DR AC
LD Y
\ AC Y
ADD
\ AC AC รพ DR
ST Z
\ Z AC
STOP
X
W
350
\ reserve a word initialized to 350
Y
W
96
\ reserve a word initialized to 96
Z
W
0
\ result stored here
Example 2
In this example, we will write an assembly program to perform
the multiplication operation: Z
X Y, where X, Y, and Z are memory
locations.
As you know, the assembly of the simple CPU does not have a multiplication
operation. We will compute the product by applying the add operation multiple
times. In order to add Y to itself X times, we will use N as a counter that is initialized
to X and decremented by one after each addition step. The BZ instruction will be
used to test for the case when N reaches 0. We will use a memory location to
store N but it will need to be loaded into AC before the BZ instruction is executed.
We will also use a memory location ONE to store the constant 1. Memory location Z
will have the partial products and eventually the final result.
The following is the assembly program using the assembly language of
our simple processor. We will assume that the values of X and Y are
small enough to allow their product to be stored in a single word. For the
sake of this example, let us assume that X and Y are initialized to 5 and 15,
respectively.
Search WWH ::




Custom Search