Hardware Reference
In-Depth Information
or high-level language statements. If an algorithmic step (or a block in the flowchart) requires
many assembly instructions or high-level language statements to implement, then it might
be beneficial either to convert this step (or block) into a subroutine and just call the sub-
routine or to further divide the algorithmic step (or flowchart block) into smaller steps (or
blocks) so that it can be coded with just a few assembly instructions or high-level language
statements.
The next major step is testing the program . Testing a program means testing for anoma-
lies. The first test is for normal inputs that are always expected. If the result is what is ex-
pected, then the borderline inputs are tested. The maximum and minimum values of the
input are tested. When the program passes this test, then illegal input values are tested. If the
algorithm includes several branches, then enough values must be used to exercise all the pos-
sible branches. This is to make sure that the program will operate correctly under all possible
circumstances.
In the rest of this topic, most of the problems are well defined. Therefore, our focus is on
how to design the algorithm that solves the specified problem as well as how to convert the
algorithm into source code.
2.5 Writing Programs to Do Arithmetic
In this section, we use small programs that perform simple computations to demonstrate
how a program is written.
Example 2.3
Write a program to add the numbers stored at memory locations $1000, $1001, and $1002
and store the sum at memory location $1010.
Solution: This problem can be solved by the following steps:
Step 1
Load the contents of the memory location at $1000 into accumulator A.
Step 2
Add the contents of the memory location at $1001 into accumulator A.
Step 3
Add the contents of the memory location at $1002 into accumulator A.
Step 4
Store the contents of accumulator A at memory location $1010.
These steps can be translated into the as12 assembly program as follows:
org
$1500
; starting address of the program
ldaa
$1000
; A [$1000]
adda
$1001
; A [A] 1 [$1001]
adda
$1002
; A [A] 1 [$1002]
staa
$1010
; $1010 [A]
end
 
Search WWH ::




Custom Search