program TestGlobalProc6c {
section module {
}
section data {
int rax = 0
int rbx = 0
int rcx = 0
int rdx = 0
string str_0 = "before: moves="
string str_1 = "after 1: moves="
string str_2 = "after 2: moves="
string fmt_int = "%lld "
string fmt_str = "%s "
string newline = "\n"
int moves = 0
int knight_row = 0
int knight_col = 0
ptr seq_row = null
ptr seq_col = null
int tour_over = 0
int i = 0
int next_move_nr = 0
int next_move_nc = 0
}
section code {
start:
alloc seq_row, 8, 64
alloc seq_col, 8, 64
mov moves, 1
mov tour_over, 0
mov knight_row, 0
mov knight_col, 0
mov i, 0
FOR_0:
cmp i, 63
jg ENDFOR_1
mov rbx, i
div rbx, 8
cmp i, 0
jl IDX_OOB_4
cmp i, 63
jg IDX_OOB_4
jmp IDX_OK_3
IDX_OOB_4:
exit 1
IDX_OK_3:
mov rcx, i
store rbx, seq_row, rcx, 8
mov rcx, i
mod rcx, 8
cmp i, 0
jl IDX_OOB_6
cmp i, 63
jg IDX_OOB_6
jmp IDX_OK_5
IDX_OOB_6:
exit 1
IDX_OK_5:
mov rdx, i
store rcx, seq_col, rdx, 8
FOR_CONTINUE_2:
add i, 1
jmp FOR_0
ENDFOR_1:
print fmt_str, str_0
print fmt_int, moves
print newline
push rbx
push rcx
call PROC_next_move
pop rcx
pop rbx
print fmt_str, str_1
print fmt_int, moves
print newline
push rbx
push rcx
call PROC_next_move
pop rcx
pop rbx
print fmt_str, str_2
print fmt_int, moves
print newline
free seq_row
free seq_col
done
function PROC_next_move:
mov rbx, moves
load rcx, seq_row, rbx, 8
mov next_move_nr, rcx
mov rbx, moves
load rdx, seq_col, rbx, 8
mov next_move_nc, rdx
mov knight_row, next_move_nr
mov knight_col, next_move_nc
add moves, 1
cmp moves, 64
jl ELSE_7
mov tour_over, 1
ELSE_7:
PROC_END_next_move:
ret
}
}