Information Technology Reference
In-Depth Information
latter scheme is called memory-mapped Input / Output. Among the advantages of
memory-mapped I
O is the ability to execute a number of memory-dedicated
instructions on the registers in the I
/
O devices in addition to the elimination of
/
the need for dedicated I
O instructions. Its main disadvantage is the need to dedicate
part of the memory address space for I
/
O devices.
/
2.4. PROGRAMMING EXAMPLES
Having introduced addressing modes and instruction types, we now move on to
illustrate the use of these concepts through a number of programming examples.
In presenting these examples, generic mnemonics will be used. This is done in
order to emphasize the understanding of how to use different addressing modes in
performing different operations independent of the machine used. Applications of
similar principles using real-life machine examples are presented in Chapter 3.
Example 1
In this example, we would like to show a program segment that can be
used to perform the task of adding 100 numbers stored at consecutive memory loca-
tions starting at location 1000. The results should be stored in memory location 2000.
CLEAR R 0 ;
R 0 0
MOVE # 100, R 1 ;
R 1 100
CLEAR R 2 ;
R 2 0
LOOP:
ADD 1000(R 2 ), R 0 ;
R 0 R 0 þ M (1000 þ R 2 )
INCREMENT R 2 ;
R 2 R 2 þ
1
DECREMENT R 1 ;
1
BRANCH-IF . 0LOOP; GO TO LOOP if contents of R 1 . 0
STORE R 0 , 2000;
R 1 R 1
M(2000)
R 0
In this example, use has been made of immediate (MOVE #100, R 1 )andindexed(ADD
1000(R 2 ), R 0 ) addressing.
Example 2
In this example autoincrement addressing will be used to perform the
same task performed in Example 1.
CLEAR R 0 ;
R 0 0
MOVE # 100, R 1 ;
R 1 100
CLEAR R 2 ;
R 2 0
LOOP: ADD 1000(R 2 )
þ
, R 0 ;
R 0 R 0 þ M (1000 þ R 2 )
& R 2 R 2 þ
1
DECREMENT R 1 ;
1
BRANCH-IF . 0 LOOP; GO TO LOOP if contents of R 1 . 0
STORE R 0 , 2000;
R 1 R 1
M(2000)
R 0
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
/
Search WWH ::




Custom Search