将C转换为ARM程序集

时间:2014-04-16 17:15:04

标签: c assembly arm translate

所以我在C中有这个代码解决了数独板,我想把它翻译成一个汇编程序,从文件board.txt中读取一块板。输出应该是打印到stdout输出的相同格式的解决板我正在使用Jgrasp,所以我想知道是否有一种方法可以转换它,还是我必须在我的代码中逐行转换并将其转换为ARM?

这是c代码:

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;
}

1 个答案:

答案 0 :(得分:2)

有免费的编译器(例如GCC)可以使用ARM代码并将其转换为汇编。如果你使用GCC,我认为你只需要使用-S选项。