I am trying to learn assembly my self, and I have been reading different websites first to know the meaning of some registers, if-the, etc, and saw examples on how to use them.
However I don’t find it easy to understand. This program finds certain letters and counts them in a board using a bidimensional array. I want to replace the part of the functions void print_results(), and void count() with assembly code since this is very easy in regular C code.
I am not sure how to start so I am more interested on just a good start, specially on how to pass the variable from void read_board() to the function void count() to count the letters found, after that I think I can be on my own.
I appreciate any help, Thank you.
#include <stdio.h>
FILE *inputFilePtr;
char board[7][7];
void usage() {
printf("usage: one filename argument.\n");
}
void read_board() {
int i, j;
for (i=0; i != 7; i++) {
for (j=0; j != 7; j++) {
fscanf(inputFilePtr, "%c", &board[i][j]);
}
fscanf(inputFilePtr, "\n");
}
}
void count() {
__asm__("\
");
}
void print_results() {
}
int main(int argc, char**argv) {
if (argc != 2) {
usage();
return 1;
}
inputFilePtr = fopen(argv[1], "r");
if (inputFilePtr == NULL) {
printf("Couldn't open file, %s\n", argv[1]);
return 1;
}
read_board();
count();
print_results();
return 0;
}
I am assuming you want the C-equivalent that does your current asm part.
Since you array board is global and your board size is fixed (7×7), you don’t need pass anything to count(). This will do:
Then simply call count() from wherever you want.
In case if you want to know how to pass parameters to functions (if the board, i & j are not global like your case):
call count as:
count(&board[0][0], int i, int j);Receive the parameters as:
void count(char **board, int i, int j)