Hussain HamadahECE 2210- G. N. Desouza14054006

Lab description :

Given an array of a random length and consisting of 8-bit two’s complement integers, we need to write and test a program to categorize all the elements of the array into 2 different types: positive integers and negative integers without the zero. The number of elements in the input array must be soft-coded – that is, I have to write acode to tell the length of the array. Also, the number of elements in the input array should never be larger than 64 – if it is, the program should exit with an error.The program must output the two arrays of categorized elements as well as the number of elements in each array. That is, it must output, say, POSITIVE_DATA, NEGATIVE_DATA, NUM_POS, and NUM_NEG, for the array of positive elements, the array of negative elements, the number of positive elements and the number of negative elements, respectively. The fifth output parameter of the program is, say, ERROR – which should be equal to 0 if no errors were found and 1 otherwise.

Requirements : The program must begin at $C000,The data array must begin at $D000

Pseudocode :Begin

Load resgister X with the data address

LOOP

Load data into acc A

Increment Register X

Test acc A

If acc A is positive, branch to POSITIVE

Load adress of negative array into Register Y

Increment Register Y

Store Register Y into NEGATIVE_DATA

Store acc A into negative array

Subtract #$FF from acc A

If the previous instruction result is zero, branch to DONE

Otherwise, always branch to LOOP

POSITIVE

Load adress of positive array into Register Y

Store acc A into positive array

Increment Register Y

Store Register Y into POSITIVE_DATA

Always branch to LOOP

DONEAlways branch to DONE

End

Flow chart : althogh

TESTING :

Set # 1 : 36,-69,-47,100,01,0,-23,-35,-89,-32,91,0,111,30,99,-36,74,85,93 > and using a constant to compare (NUM_EL FCB19 )WITH slight change in the code,the B register to count how many numbers have you organized ,and compare it to the NUM_EL. If greater than branch to ERRORas we can see the number of nigative # is 7 and the positive # is $A (A in hexadeciamal = 10 in decimal ) and since there are two zeros , they have excuded ( 7 + 10 + two zeros = 19 number ). If you can see the (memory watch ),although I am using a different names for num_positive and num_negative the wookie works fine because the programe just need the right address.

S / X / H / I / N / Z / V / C
0 / 1 / 1 / 1 / 0 / 1 / 0 / 0

Set #2 : 36,-69,-47,100,01,0,-23,-35,-89,-32,91,0,111,30,99,-36,74,85,93,$FF >without using the constant to compare (NUM_EL FCB19 )as we can see the number of nigative # is 7 and the positive # is $A (A in hexadeciamal = 10 in decimal ) . it is just the same results as the first test. I have used the numver ($FF) to tell the programe that you have reached the end of the array

S / X / H / I / N / Z / V / C
0 / 1 / 1 / 1 / 0 / 1 / 0 / 0

Set #3 : now I am testing to see if the programe react toword longer array . I have just repeated the given array 5 times ( 19 *5 ) = 95 elements in the array . as we can see the positive numbers equal to ($28 = 40 Dec ) and negatives ( $18 = 24 Dec) which equal to (64 in Dec) which is also the limite of longest possible array. And the error has been set to #1 because the array was more than 64 elements. THE SET,<36,-69,-47,100,01,0,-23,-35,-89,-32,91,0,111,30,99,-36,74,85,93,36,-69,-47,100,01,0,-23,-35,-89,-32,91,0,111,30,99,-36,74,85,93,36,-69,-47,100,01,0,-23,-35,-89,-32,91,0,111,30,99,-36,74,85,93,36,-69,-47,100,01,0,-23,-35,-89,-32,91,0,111,30,99,-36,74,85,93,36,-69,-47,100,01,0,-23,-35,-89,-32,91,0,111,30,99,-36,74,85,93 >

S / X / H / I / N / Z / V / C
0 / 1 / 1 / 1 / 0 / 0 / 0 / 0

The Code : for any array

*************************************************************************

* Name: Hussain Hamadah

* Student #: 14054006

* Lab 3: array of 8-bit long numbers.

* Date: 3/21/08

* Description: This program categorize set of number into two different arrays. One array

* with only positive numbers and the other one with only negative numbers.

* Pseudocode:Begin

*Load resgister X with the data address

*LOOP

*Load data into acc A

*Increment Register X

*Test acc A

*If acc A is positive, branch to POSITIVE

*Load adress of negative array into Register Y

*Increment Register Y

*Store Register Y into NEGATIVE_DATA

*Store acc A into negative array

*Subtract #$FF from acc A

*If the previous instruction result is zero, branch to DONE

*Otherwise, always branch to LOOP

*POSITIVe

*Load adress of positive array into Register Y

*Store acc A into positive array

*Increment Register Y

*Store Register Y into POSITIVE_DATA

*Always branch to LOOP

*DONE

*Always branch to DONE

* end

*

*************************************************************************

***** Data Section *****

ORG$D000

DATA FCB 36,-69,-47,100,01,0,-23,-35,-89,-32,91,0,111,30,99,-36,74,85,93,$FF

POSITIVE_DATAFDB$D040define address of positive array

NEGATIVE_DATAFDB$D080define address of negative array

ORG$D0C0

NUM_POSITIVERMB1

NUM_NEGATIVERMB1

ERRORRMB1

***** PROGRAM STARTS HERE *****

ORG $C000Program starts at $C000

CLRNUM_POSITIVE

CLRNUM_NEGATIVE

LDX#DATALoad registe X with data address

ENDIF_POS

LOOPLDAA0,XLoad data into acc A

CMPA#$FFSubtract #$FF from acc A

BEQDONEbranch to DONE if the previous instruction result is zero

LDABNUM_POSITIVE

ADDBNUM_NEGATIVE

CMPB#64

BEQSIZE_ERROR

LDAA 0,X

INXIncrement register X

TSTATest acc A

BEQLOOP

BPLIF_POSITIVEBranch to POSITIVE if acc A is positive

LDYNEGATIVE_DATALoad register Y with address of negative array

STAA0,YStore acc A into negative array

INYIncrement Register Y

STYNEGATIVE_DATAStore Registe Y into NEGATIVE_DATA

INCNUM_NEGATIVE

BRALOOPAlways branch to LOOP

IF_POSITIVE

LDYPOSITIVE_DATALoad register Y with address of positive array

STAA0,YStore acc A into positive array

INYIncrement register Y

STYPOSITIVE_DATAStore Register Y into POSITIVE_DATA

INCNUM_POSITIVE

BRAENDIF_POSAlways branch to ENDIF_POS

SIZE_ERROR

LDAA #1 Set error flag

STAA ERROR

DONE BRA DONE Infinite loop

END

Conclusion :

Dealing with arrays that have signed numbers is easy if some signed branch instructions are used . the important thing is using the registers the rights way and not wasting memory .