Решение судоку в armv8, который печатает числа до 13 вместо 9
Ниже приведен код Java, который я пытаюсь преобразовать в armv8. Код armv8 - моя работа. Кажется, он не работает должным образом, так как в настоящее время он использует цифры от 1 до 13, в то время как судоку следует использовать только цифры 1-9.
У меня есть статическая таблица, которая инициализируется случайными числами от 1 до 9 и некоторыми нулями. эти нули должны быть заменены во время игры программой.
private boolean isAllowed(int row, int col,int number)
{
return !(containsInRow(row, number) || containsInCol(col, number) || containsInBox(row, col, number));
}
public boolean solveSudoku()
{
for(int row=0;row<9;row++)
{
for(int col=0;col<9;col++)
{
if(sudoku[row][col]==UNASSIGNED)
{
for(int number=1;number<=9;number++)
{
if(isAllowed(row, col, number))
{
sudoku[row][col] = number;
if(solveSudoku())
{
return true;
}
else
{
sudoku[row][col] = UNASSIGNED;
}
}
}
return false;
}
}
}
return true;
}
Версия кода сборки, которую я создал:
solveSudoku:
stp x29,x30,[sp,-32]!
add x29,sp,0
mov w19,0 //w19=Register for rows
mov w20,0 //w20=Register for col
mov w24,1 //w24=register for numbers
solve:
adrp x0,tab
add x0,x0,:lo12:tab
mov w27,9
and w22,w22,wzr //set 0 to w22
mul w22,w27,w19
add w22,w22,w20
lsl w22,w22,2 //calculate the table position
ldr w23,[x0,x22] //w23=number in specific position in the table(position calculate above in w22)
cbnz w23,.incCol //if is not zero go to label .incCol to increase the j
// mov w24,1
nums:
mov w2,w19
mov w6,w24
bl containsInRow //check if number contains in a row
mov w25,w7
mov w2,w20
mov w6,w24
bl containsInCol //check if number contains in a col
mov w26,w7
mov w2,w19
mov w3,w20
mov w4,w24
bl containsInBox //check if number contains in a box
mov w28,w5
mov w1,w25
mov w2,w26
mov w3,w28
bl isAllowed //if number is allow to be place in specific position
mov w28,w5
cbz w28,.next //if is not allow go to next number
and w25,w25,wzr
mul w25,w27,w19
add w25,w25,w20
lsl w25,w25,2
str w24,[x0,x25] //store number from register w24 in position calculate above
bl solveSudoku
cbnz w21,.end //if is not zero move to check register w21=1 and return
str wzr,[x0,x25] //if is zero store zero to the position had changed above
b .next
.next:
add w24,w24,1 //increase number
cmp w24,10 //if number is 10 set register w21 to 0 and return
b.eq .again
b nums //go back to check next number
.incCol:
add w20,w20,1 //increase col
cmp w20,9 //if col is 9 go to increase rows
b.eq .incLine
b.ne solve //if is not 9 go back to check next column
.incLine:
sub w20,w20,9 //set col back to 0
add w19,w19,1 //increase row
cmp w19,9 //if row is 9 set register w21 to 1 and return
b.eq .end
b.ne solve //if is not 9 go back to check next row
.again:
mov w21,0 //return false
ldp x29,x30,[sp],32
ret
.end:
mov w21,1 //return true
ldp x29,x30,[sp],32
ret
Результаты Судоку: