Commit 1674a9b8 by kjc015

### Lab 07 Complete

parent fd3f11dd
 all: counte primes2 matrix_sum CC=gcc CFLAGS=-Wall -Werror primes2: primes2.o \$(CC) \$(CFLAGS) primes2.c is_prime.s -o primes2 counte: counte.o \$(CC) \$(CFLAGS) counte.c counte.s -o counte matrix-sum: matrix-sum.o \$(CC) \$(CFLAGS) matrix-sum-main.c matrix-sum.s -o matrix-sum time: time.o \$(CC) \$(CFLAGS) time.c time.s -o time
 #include #include int counte(char* string); int main(){ char input[30]; printf("Enter a string: "); fgets(input, 30, stdin); printf("There are %d e's\n", counte(input)); return 0; }
 .globl counte .data character: .asciz "e" .text counte: la s2, character lb s2, 0(s2) j find # call find find: lb t2, 0(a0) #load the first character of the string into t2 addi a0, a0, 1 #increment to next character in string beq t2, s2, found #branch if the character is found beq t2, zero, exit #branch if we reach the end of the string (null character) j find found: addi s3, s3, 1 #add 1 to sum j find exit: mv a0, s3 #move sum to a0 for return jr ra #return to original function call
 #include extern void matrix_sum(int A[2][3], int B[2][3], int C[2][3]); int print_m (int x[2][3]) { int i,j; for (j = 0; j < 2; j++){ for (i = 0; i < 3; i++){ printf("%d ", x[j][i]); } printf ("\n"); } printf ("\n"); return 0; } int main(void) { int A[2][3] = {{0, 1, 2}, {9, 8, 7}}; int B[2][3] = {{6, 5, 4}, {3, 4, 5}}; // int C[2][3] = {{0, 0, 0}, {0, 0, 0}}; int C[2][3] = {0}; print_m(A); print_m(B); matrix_sum(A,B,C); print_m(C); return 0; }