University of Missouri



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 $D000Pseudocode :BeginLoad resgister X with the data addressLOOPLoad data into acc AIncrement Register XTest acc AIf acc A is positive, branch to POSITIVELoad adress of negative array into Register YIncrement Register YStore Register Y into NEGATIVE_DATAStore acc A into negative arraySubtract #$FF from acc AIf the previous instruction result is zero, branch to DONEOtherwise, always branch to LOOP POSITIVELoad adress of positive array into Register YStore acc A into positive arrayIncrement Register YStore Register Y into POSITIVE_DATAAlways branch to LOOPDONEAlways branch to DONE EndFlow chart : althogh startX = y = z = count =0 ; arrayend = $ff =-1?yesnoyesyesnoyesnonoCount > 64N = arrayend X = X + 1 Y = Y + 1 N > 0 Count = count + 1N > 127 or N < -128Show X , Y END Get a number ( N ) from the arrayTESTING :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 FCB?19 )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 ERROR as 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. SXHINZVC01110100Set #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 FCB?19 )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 SXHINZVC01110100Set #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 >SXHINZVC01110000 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$D000DATA FCB 36,-69,-47,100,01,0,-23,-35,-89,-32,91,0,111,30,99,-36,74,85,93,$FFPOSITIVE_DATAFDB$D040define address of positive arrayNEGATIVE_DATAFDB$D080define address of negative arrayORG$D0C0NUM_POSITIVERMB1NUM_NEGATIVERMB1ERRORRMB1***** PROGRAM STARTS HERE *****ORG $C000Program starts at $C000CLRNUM_POSITIVECLRNUM_NEGATIVELDX#DATALoad registe X with data addressENDIF_POSLOOPLDAA0,XLoad data into acc ACMPA#$FFSubtract #$FF from acc ABEQDONEbranch to DONE if the previous instruction result is zeroLDABNUM_POSITIVEADDBNUM_NEGATIVECMPB#64BEQSIZE_ERRORLDAA 0,XINXIncrement register XTSTATest acc ABEQLOOPBPLIF_POSITIVEBranch to POSITIVE if acc A is positiveLDYNEGATIVE_DATALoad register Y with address of negative arraySTAA0,YStore acc A into negative arrayINYIncrement Register YSTYNEGATIVE_DATAStore Registe Y into NEGATIVE_DATA INCNUM_NEGATIVEBRALOOPAlways branch to LOOPIF_POSITIVELDYPOSITIVE_DATALoad register Y with address of positive arraySTAA0,YStore acc A into positive arrayINYIncrement register YSTYPOSITIVE_DATAStore Register Y into POSITIVE_DATAINCNUM_POSITIVEBRAENDIF_POSAlways branch to ENDIF_POSSIZE_ERROR LDAA #1 Set error flag STAA ERRORDONE BRA DONE Infinite loop ENDConclusion : 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 . ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download