Lec4 Computer Architecture
Lec4 Computer Architecture
lec4
2.4. Programming Examples
2
• The results should be stored in memory
location 2000.
• In this example, use has been made of
immediate (MOVE #100, R1) and indexed
(ADD 1000(R2), R0) addressing.
3
• As can be seen, a given task can be performed
using more than one programming
methodology. The method used by the
programmer depends on his/her experience
4
• Example 3 This example illustrates the use of
a subroutine, SORT, to sort N values in
ascending order (Fig. 2.13).
• The numbers are originally stored in a list
starting at location 1000.
• The sorted values are also stored in the
same list and again starting at location 1000.
• The subroutine sorts the data using the
well-known “Bubble Sort” technique.
• The content of register R3 is checked at the
end of every loop to find out whether the
list is sorted or not.
5
6
• Example 4 This example illustrates the use of
a subroutine, SEARCH, to search for a value
VAL in a list of N values (Fig. 2.14).
• We assume that the list is not originally
sorted and therefore a brute force search is
used.
• In this search, the value VAL is compared with
every element in the list from top to bottom.
• The content of register R3 is used to indicate
whether VAL was found.7
8
• Example 5 This example illustrates the use of a
subroutine, SEARCH, to search for a value VAL
in a list of N values (as in Example 4) (Fig.
2.15). Here, we make use of the stack to send
the parameters VAL and N.
9
10
In this lecture
– 5.1. CPU Basics 83
– 5.2. Register Set 85
5.1. CPU Basics… 83
Fetch operands
Move them to Ri
Execute ins.
Index Register
• Index Register, the address of the operand is
obtained by adding a constant to the content of a
register, called the index register.
• The index register holds an address displacement.
• Index addressing is indicated in the instruction by
including the name of the index register in
parentheses and using the symbol X to indicate
the constant to be added.
Segment Pointer