0

I'm trying to pass some arguments into a function but it doesn't get them correctly. I want to multiply some matrices and I want to pass: address of matrix 1, address of matrix 2, address of the matrix i want the result to be in, and the size of the matrix.

matrix_mult:
pushl %ebp
pushl %ebx
pushl %edi
pushl %esi
movl %esp, %ebp

movl 8(%ebp), %edi
movl 12(%ebp), %esi
movl 16(%ebp), %ebx
movl 20(%ebp), %ecx

*the rest of the algorithm*

After those lines, the values in edi, esi, ebx, ecx are all wrong.

The function calling looks like this - trying to multiply matrix by itself and storing the result into matrix2. The matrix and msizze are stored correctly.

main:
*reading msize and matrix*

pushl msize
pushl $matrix2
pushl $matrix
pushl $matrix
call matrix_mult
addl $16, %esp

In the debugger it shows me that: edi = 2 esi = big negative value ebx = big positive value ecx = big positive value

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Iustin
  • 70
  • 5
  • 2
    You did `movl %esp, %ebp` after pushing some registers, but didn't adjust the offsets to still access your incoming stack args (which were originally at `4(%esp)`, then `8(%esp)` after one push, and higher after more pushes). This is why we normally set up the frame pointer to point at the saved EBP, as a standard reference point. – Peter Cordes Jan 05 '23 at 10:44
  • so moving the `movl %esp, %ebp` before the pushes solves the problem – Iustin Jan 05 '23 at 10:52

0 Answers0