So i have this code in C that solves a Sudoku board and I want to translate it into an assembly program that reads a board from the file board.txt Output should be the solved board in the same format printed to the stdout output.I am using Jgrasp so I was wondering if there was a way to just convert it or do i have to just go line by line in my code and translate it to ARM?
here is the c code:
int rowOK(int board[9][9], int row) {
int index;
int count[10];
for (index=0; index<10; index++)
count[index] = 0;
for (index=0; index<9; index++)
count[board[row][index]]++;
for (index=1; index<10; index++)
if (count[index] > 1)
return 0;
return 1;
}
int colOK(int board[9][9], int col) {
int row;
int seen=0x0;
for (row=0; row<9; row++){
if ((board[row][col] != 0) &&
(seen&(0x1<<board[row][col] == 1)))
return 0;
else
seen=seen|(0x1<<board[row][col]);
}
return 1;
}
int boxOK(int board[9][9], int row, int col) {
int roff;
int coff;
int seen = 0x0;
for (roff=0; roff<3; roff++)
for (coff=0; coff<3; coff++)
if ((board[row+roff][col+coff] != 0) &&
((seen & (0x1 << board[row+roff][col+coff])) != 0))
return 0;
else
seen = seen | (0x1 << board[row+roff][col+coff]);
return 1;
}
int status(int board[9][9]) {
int index;
int row;
int col;
for (index=0; index<9; index++)
if ((rowOK(board,index) == 0) ||
(colOK(board,index) == 0))
return 0;
for (row=0; row<9; row=row+3)
for (col=0; col<9; col=col+3)
if (boxOK(board,row,col) == 0)
return 0;
return 1;
}
int solve(int board[9][9]) {
int guess;
int row;
int col;
int emptyrow = -1;
int emptycol = -1;
for (row=0; row<9; row++)
for (col=0; col<9; col++)
if (board[row][col] ==0) {
emptyrow = row;
emptycol = col;
}
if (emptyrow < 0)
return 1;
for (guess = 1; guess<10; guess++) {
board[emptyrow][emptycol] = guess;
if (status(board) == 1)
if (solve(board) == 1)
return 1;
}
return 0;
}
There are free compilers available (such as GCC) that can take ARM code and convert it into assembly for you. If you use GCC, I think you just need to use the -S
option.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.