Hey guys, I've got a question.
I have a function in C, matmulss, that passes three float[][] as arguments, like so:
float[][] A, B, C
matmulss(A,B,C)
matmulss is a function I'm writing in x86-64 assembly, using GAS.
My question is, how are these arguments passed? Is it passing the A[0][0], B[0][0], C[0][0], to my assembly or is it passing memory addresses?
I don't see why it would be memory addresses since it's not a pointer though...
Any help?
Thanks!
Argument Passing in C
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: Argument Passing in C
Obviously its the address .
Re: Argument Passing in C
The C standard says that if an array name is used in an expression without an index following it, its value becomes to a pointer to the first element in the array. That's why you can pass strings to a char* easily. It also lets you do stuff like this:
Code: Select all
const char* a = "Hi!"; // Creates a pointer that points to the 'H'
Re: Argument Passing in C
Alright, thanks!
Let me ask you another question then.
I'm trying to do some multiplication using the xmm registers.
However, when I code:
movss (%rdi), %xmm0
I get a segmentation fault...
I'm trying to load the value of A[0][0] (which I'm assuming is being given to me as an address by the argument) into the xmm0 register.
Any idea how to fix this?
Let me ask you another question then.
I'm trying to do some multiplication using the xmm registers.
However, when I code:
movss (%rdi), %xmm0
I get a segmentation fault...
I'm trying to load the value of A[0][0] (which I'm assuming is being given to me as an address by the argument) into the xmm0 register.
Any idea how to fix this?
Hexciting: An open source hex editor for the command line.
https://sourceforge.net/projects/hexciting/
https://sourceforge.net/projects/hexciting/
Re: Argument Passing in C
The variable A is a pointer which points to an array of pointers. You needsamoz wrote: I'm trying to load the value of A[0][0] (which I'm assuming is being given to me as an address by the argument) into the xmm0 register.
Code: Select all
mov rax, A ; could be mov rax, [rsp + 16] or mov rax, rcx or whatever the calling convention is
; rax now points to an array of pointers
mov rax, [rax +0] ; load pointer to first row
mov xmm0, [rax +0] ; load first element in array
Code: Select all
mov rax, A ; could be mov rax, [rsp + 16] or mov rax, rcx or whatever the calling convention is
; rax now points to an array of pointers
mov rax, [rax +8] ; load pointer to second
mov xmm0, [rax +8*2] ; load third element in array
Last edited by ru2aqare on Mon Nov 10, 2008 6:08 am, edited 1 time in total.
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: Argument Passing in C
C uses row - major addressing .
Regards
Sandeep
Regards
Sandeep