* Lorenzo Windmoller, Nicolas Salles, Tómas Onofrio, Vitor Espindola * * Program "ContaPares" with goal to count the quantity of even numbers * in a vector with a static size. * * Code in C Language is: * * 1. int conta_pares(int *vector, int size) { * 2. int count = 0; * 3. for (int i = 0; i < size; i++) { * 4. if (vector[i] % 2 == 0) * 5. count++; * 6. } * 7. return count; * 8. } * * ============================================================================================= ORG $0000 ;define start address * ============================================================================================= size EQU &20 ;define label size with 20 vector RMB size ;declare vector with size 20, for 10 numbers w/ 2 bytes count RMB &02 ;declare counter with 2 bytes pos RMB &02 ;declare position controller with 2 bytes * ============================================================================================= initialize CLR count ;clear content in count address CLR pos ;clear content in pos address * ============================================================================================= load_values LDX #vector ;load index register X with vector address LDD #&20 ;load accumulator D with '0d20' STD 0,x ;store accumulator D in position 0-1 of the vector LDD #&53 ;load accumulator D with '0d53' STD 2,x ;store accumulator D in position 2-3 of the vector LDD #&11 ;load accumulator D with '0d11' STD 4,x ;store accumulator D in position 4-5 of the vector LDD #&8 ;load accumulator D with '0d8' STD 6,x ;store accumulator D in position 6-7 of the vector LDD #&12 ;load accumulator D with '0d12' STD 8,x ;store accumulator D in position 8-9 of the vector LDD #&0 ;load accumulator D with '0d0' STD 10,x ;store accumulator D in position 10-11 of the vector LDD #&36 ;load accumulator D with '0d36' STD 12,x ;store accumulator D in position 12-13 of the vector LDD #&0 ;load accumulator D with '0d0' STD 14,x ;store accumulator D in position 14-15 of the vector LDD #&9 ;load accumulator D with '0d9' STD 16,x ;store accumulator D in position 16-17 of the vector LDD #&22 ;load accumulator D with '0d22' STD 18,x ;store accumulator D in position 18-19 of the vector * ============================================================================================= loop LDAB pos ;load accumulator B with pos controller address LDX #vector ;load index register X with vector address ABX ;increment position in vector LDD 0,x ;load accumulator D with vector content * ============================================================================================= is_even LDX #2 ;load index register X with number 2 (divisor) IDIV ;calculate integer division of accumulator D by X CPD #0 ;compare accumulator D (became remainder) with 0 BEQ increment ;go to loop if comparison result is equal to 0 JMP continue ;go to continue section, jumping the counter increment * ============================================================================================= increment LDAA count ;load accumulator A with counter address INCA ;increment counter STAA count ;store accumulator A, saving the new counter value * ============================================================================================= continue LDAA pos ;load accumulator A with pos controller address INCA ;increment counter, going to the first next byte INCA ;increment counter, going to the second next byte STAA pos ;store accumulator A, saving the new current position CMPA #size ;compare accumulator A with vector size BNE loop ;go to loop if comparison result is not equal to 0 * ============================================================================================= END