I implemented all the "for" loops and I have an infinite cycle. I tried my best, but I can not find the problem, please help. I just want my loops to work. Please help. This is the code
.data
m1: .long 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0
m2: .long 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0
mres: .long 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
n: .long 4
fs: .asciz "%ld"
.text
matrix_mult:
pushl %ebp
mov %esp, %ebp
pushl %edi
pushl %esi
pushl %ebx
subl $12, %ebp
// -16(ebp) = i
// -20(ebp) = j
// -24(ebp) = k
subl $8, %ebp
// -28(ebp) = x
// -32(ebp) = y locul unde stocam elem din cele 2 matrici
movl $0, -16(%ebp)
movl $0, -20(%ebp)
movl $0, -24(%ebp)
et_for1:
mov -16(%ebp), %eax
mov 20(%ebp), %ecx
cmp %eax, %ecx
jge final
movl $0, -20(%ebp)
et_for2:
mov -20(%ebp), %eax
mov 20(%ebp), %ecx
cmp %eax, %ecx
jge cont_for2
movl $0, -24(%ebp)
et_for3:
mov -24(%ebp), %eax
mov 20(%ebp), %ecx
cmp %eax, %ecx
jge cont_for3
//mres[i][j]=m1[i][k]*m2[k][j]
lea 8(%ebp), %edi
lea 12(%ebp), %esi
//ecx=i*n+k, ecx= indicele pt m1
mov -16(%ebp), %eax
xorl %edx, %edx
mull 20(%ebp)
addl -24(%ebp), %eax
mov %eax, %ecx
//eax=k*n+j, eax= indicele pt m2
mov -24(%ebp) , %eax
xorl %edx, %edx
mull 20(%ebp)
addl -20(%ebp), %eax
//ecx = produsul termenilor
mov (%edi, %ecx, 4), %ebx
mov %ebx, -28(%ebp)
mov (%esi, %eax, 4), %ebx
mov %ebx, -32(%ebp)
mov -28(%ebp), %eax
xorl %edx, %edx
mull -32(%ebp)
mov %eax, %ecx
//eax=i*n+j
movl -16(%ebp), %eax
xorl %edx, %edx
mull 20(%ebp)
movl -20(%ebp), %ebx
addl %ebx, %eax
//ecx= prod term + mres[i][j]
lea 16(%ebp), %edi
movl (%edi, %eax, 4), %ebx
movl %ebx, -28(%ebp)
addl -28(%ebp), %ecx
movl %ecx, (%edi, %eax, 4)
mov -24(%ebp), %ebx
incl %ebx
mov %ebx, -24(%ebp)
//k++
jmp et_for3
cont_for3:
mov -20(%ebp), %ebx
incl %ebx
mov %ebx, -20(%ebp)
mov $0, -24(%ebp)
//j++ si k=0
jmp et_for2
cont_for2:
mov -16(%ebp), %ebx
incl %ebx
mov %ebx, -16(%ebp)
//i++
jmp et_for1
final:
addl $20, %esp
popl %ebx
popl %esi
popl %edi
popl %ebp
ret
.global main main:
pushl n
pushl mres
pushl m2
pushl m1
call matrix_mult
addl $16, %esp
lea mres, %edi
mov $0, %ecx
mov n, %eax
xorl %edx, %edx
mull %eax
//eax=n*n
et_for:
cmp %eax, %ecx
je et_exit
mov (%edi, %ecx, 4), %ebx
pushl %eax
pushl %ecx
//afisare ebx
push %ebx
push $fs
call printf
addl $8, %esp
push $0
call fflush
addl $4, %esp
popl %ecx
popl %eax
incl %ecx
jmp et_for
et_exit:
mov $1, %eax
xorl %ebx, %ebx
int $0x80
I tried to print some values in order to understand better what s happening...but I can t find the problem