Lab_Assignment__3_ngkrk6_LAB3WriteUp

advertisement
ECE2210
Introduction to Digital Logic
Instructor: Prof. DeSouza
Lab Report #3
by
Nathaniel Kinsey
Lab Description:
Given an array of arbitrary size and consisting of 8-bit two’s complement integers, write and
test a program to categorize all the elements of the array into two different types: strictly
positive integers (no zeros) and strictly negative integers.
Implementation:
Here is a flowchart that describes outline of my algorithm:
Results:
The program was tested with three sets of data, one given in the lab assignment, on that should
produce an error, and one that a random assignment of numbers
Sequence 1: Given Sequence
The DATA array for this sequence contained 19 numbers. The assignment was as follows:
DATA FCB 36,-69,-47,100,01,0,-23,-35,-89,-32,91,0,111,30,99,-36,74,85,93
Num_Elm FCB 19
The program attained the expected results. The POSITIVE_DATA array contained 10 numbers
stored at $D013-$D01C, and the NEGATIVE_DATA array contained 7 numbers stored at $D053$D059. The two zeros were skipped in the program and not added to either array. The program
also ended with ERROR = 0 showing the program completed without error. The contents of the
two arrays were as follows:
POSITIVE_DATA: $24,$64,$01,$5B,$6F,$1E,$63,$4A,$55,$5D
NEGATIVE_DATA: $BB,$D1,$E9,$DD,$A7,$E0,$DC
Screenshot of the Wookie after Program completion
POSITIVE_DATA
NEGATIVE_DATA
ERROR
Sequence 2: Error Sequence
The purpose of this test is to test the programs error handling by providing more than the
allowable elements in the DATA array. I did not add 65 individual elements as this is irrelevant
for this algorithm. As long as Num_Elm is larger than the allotted amount the program will exit
with an error:
DATA
Num_Elm
FCB
FCB
00
66
The program concluded with an error as expected. This is due to the program checking to make
sure that the Num_Elm in the DATA array is in fact less than or equal to the Max_Elm which is
64. If this is false, then the program branches to ERR and exits with in $D087, ERROR = 1.
Screenshot of the Wookie after program completion
ERROR
Sequence 3: Arbitrary Sequence
The DATA array for this sequence contained 10 numbers. The assignment was as follows:
DATA
Num_Elm
FCB
FCB
24,4,-7,95,-75,102,48,0,05,-7
10
The program attained the expected results. The POSITIVE_DATA array contained 6 numbers
stored at $D00A-$D00F, and the NEGATIVE_DATA array contained 3 numbers stored at $D04A$D04C. The zero was again skipped in the program and not added to either array. The program
also ended with ERROR = 0 showing the program completed without error. The contents of the
two arrays were as follows:
POSITIVE_DATA: $18,$04,$5F,$66,$30,$05
NEGATIVE_DATA: $F9,$B5,$F9
Screenshot of the Wookie after program completion
ERROR
NEGATIVE_DATA
POSITIVE_DATA
Conclusion:
This program handles data arrays of an arbitrary length very well and also deals with two
possible errors including two’s complement overflow and greater than maximum number of
elements allowable. After having tested the program with several different sets of data and
testing error reporting, I conclude that this program completes the objective for which is was
designed properly and concisely.
Appendix A:
Assembler Source Code:
**********************************************************************************
* Name: Nathaniel Kinsey
* Student #: 08428848
* Lab 3: Check an array of numbers and sort positive and negative numbers
*
into separate arrays.
*
* Date: March 19, 2008
*
* Description: This program checks the value and each number corresponding to zero
*
and adds the number to the appropriate array.
*
*
* Pseudocode: BEGIN
*
Check Num_Elm < Max_Elm
*
Branch if positive to ERR
*
Load POSITIVE_DATA into index register x
*
Save index register x into Pos_Index
*
Load NEGATIVE_DATA into index register x
*
Save index register x into Neg_Index
*
Clear accum A and B
*
Load resgister X with the data address
*
Load zero into acc a
*
Load first value of DATA into the acc B
*
LOOP
*
Compare acc b to acc a
*
Branch if Zero to NULL
*
Branch if positive to NEGATIVE
*
Branch if negative to POSITIVE
*
Branch if Overflow to ERR
*
POSITIVE
*
POSITIVE_DATA[Pos_Index] = DATA[x]
*
Increment Pos_Index
*
Branch always to INCREMENT
*
NEGATIVE
*
NEGATIVE_DATA[Neg_Index] = DATA[x]
*
Increment Neg_Index
*
Branch always to INCREMENT
*
NULL
*
Branch always to INCREMENT
*
ERR
*
Accum A = 1
*
Store A into ERROR
*
Branch always to END
*
INCREMENT
*
Num_Elm - 1
*
Branch to SAVE if Num_Elm equal to zero
*
Increment DATA pointer
*
Load Data[x] into accum A
*
Branch always to LOOP
*
SAVE
*
Accum A = 0
*
Store A into ERROR
*
Branch always to END
*
END
*
Branch always to END
*
*************************************************************************************
***** DATA *****
DATA
POSITIVE_DATA
NEGATIVE_DATA
Num_Elm
Pos_Index RMB
Neg_Index RMB
Max_Elm
ERROR
ZERO
ORG
FCB
RMB
RMB
FCB
2
2
FCB
RMB
FCB
$D000
Origin of data at $D000
24,4,-7,95,-75,102,48,0,05,-7
data array
64
reserve memory for positive number array
64
reserve memory for negative number array
10
the number of elements in the data array
reserve memory byte for positive pointer
reserve memory byte for negative pointer
64
maximum number of allowable elements
1
reserve memory for value of error
0
constant zero
***** PROGRAM *****
ORG
LDAA
CMPA
BPL
LDX
STX
LDX
STX
CLRA
CLRB
LDX
LDAA
LDAB
$C000
Num_Elm
Max_Elm
ERR
#POSITIVE_DATA
Pos_Index
#NEGATIVE_DATA
Neg_Index
#DATA
ZERO
0,X
origin of program at $c000
load number of elements into acc a
subtract max num of elements
if this is a positive number then branch to err
load POSITIVE_DATA into index register x
store index register x into Pos_Index
load NEGATIVE_DATA into index register x
store index register x into Neg_Index
clear acc a
clear acc b
load x with data array pointer
load zero into acc a
load acc b with first number
NULL
NEGATIVE
POSITIVE
ERR
subtract acc a from acc b
if result is zero skip number
if result is positive then branch to NEGATIVE
if result is negative then branch to POSITIVE
if overflow branch to err
LOOP
CBA
BEQ
BPL
BMI
BVS
POSITIVE
LDY
LDAB
STAB
INY
STY
BRA
Pos_Index
0,X
0,Y
LDY
LDAB
STAB
INY
STY
BRA
Neg_Index
0,X
0,Y
BRA
INCREMENT
branch always to increment
LDAA
STAA
BRA
#1
ERROR
END
load acc a with $1
store acc a into ERROR
branch always to end
DEC
BEQ
INX
LDAB
BRA
Num_Elm
SAVE
0,X
LOOP
decrement Num_Elm
if previous Num_Elm = 0 branch to SAVE
increment data pointer
load next number from data into acc b
branch always to LOOP
LDAA
STAA
BRA
#0
ERROR
END
load acc a with 0
store acc a into ERROR
branch always to END
BRA
END
branch always here to end program
Pos_Index
INCREMENT
load the pointer to POSITIVE_DATA into index register y
load number from data into acc b
store acc b into POSITIVE_DATA at position y
increment POSITIVE_DATA pointer
store updated pointer
branch always to increment
NEGATIVE
Neg_Index
INCREMENT
load pointer to NEGATIVE_DATA into index register y
load number from data into acc b
store acc b into NEGATIVE_DATA at position y
increment NEGATIVE_DATA pointer
store updated pointer
branch always to increment
NULL
ERR
INCREMENT
SAVE
END
Download