* Re: extended asm+pointers [not found] <20040811112319.87376.qmail@web52908.mail.yahoo.com> @ 2004-08-11 13:04 ` sandeep 0 siblings, 0 replies; 4+ messages in thread From: sandeep @ 2004-08-11 13:04 UTC (permalink / raw) To: Ankit Jain; +Cc: linux-assembly [-- Attachment #1: Type: text/plain, Size: 2455 bytes --] Yeah, on closer look, your code should achieve what you intended. May be something more has to be done in "asm ...." to get the correct code generated or may be gcc (v 3.2.3 on i386) is not generating correct code. I tried slightly modified version of your code (attached file 1.c) also attaching the output of "gcc -S 1.c" (file 1.s - modified) original assembly code generated for the "asm(...)" in the code was #APP movq (%eax), %mm0 movq %mm0, (%eax) #NO_APP this code is not going to change things, as it is doing like "x=x". On modifying the code to below (based on how variables were allocated for the test) #APP movq (%eax), %mm0 leal -16(%ebp), %eax movq %mm0, (%eax) #NO_APP "gcc 1.s" generates a.out that works the you expect. Ankit Jain wrote: > thanks. well i know it is effectively working for > m1[i] but my question was why it is not working for > b[i] when pointer points to that location or the > reality could be pointer dont points to that > location...but if so then why? > > ankit > --- sandeep <sandeep@codito.com> wrote: > >>Ankit Jain wrote: >> >>> 4 int main() >>> 5 { >>> 6 uint8_t >>>a[8]={1,2,3,4,5,6,7,8},b[8]={0,0,0,0,0,0},i; >>> 7 uint8_t *m,*m1; >>> 8 >>> 9 m=a; >>> 10 m1=b; //i have pointed m1 to b >>> 11 for(i=0;i<8;i++) >>> 12 printf("%d ",a[i]); >>> 13 printf("\n"); >> >>> 14 asm("movq (%1), %%mm0 \n" >>> 15 "movq %%mm0, (%0) \n" >>> 16 :"=r"(m1) >>> 17 :"r"(m) >>> 18 ); >> >>this asm(...) is effectively achieving "m1=m;" you >>can verify this by printing >>m1[i] instead of a[i] and b[i] >> >>> 19 >>> 20 for(i=0;i<8;i++) >>> 21 printf("%d ",b[i]); >>> 22 return 0; >>> 23 } >>>well this problem is not solved yet. because when i >>>display b array then it prints all 0's. according to >>>me since i have initialised this m1 pointer then by b >>>then b whould have all the values which i have moved >>>some have advised me to use arrays here as constraint >>>but i want to use pointers. i am using r constraint >>>and it says it says that m1 will use a register (i >>>guess there is no problem in that) -- regards sandeep -------------------------------------------------------------------------- A lack of leadership is no substitute for inaction. -------------------------------------------------------------------------- [-- Attachment #2: 1.c --] [-- Type: text/plain, Size: 353 bytes --] #include <inttypes.h> int main() { uint32_t a[2]={0x01020304,0x05060708},b[2]={0x0,0x0},i; uint32_t *m,*m1; m=a; m1=b; //i have pointed m1 to b asm volatile ("movq (%1), %%mm0 \n" "movq %%mm0, (%0) \n" :"=r"(m1) :"r"(m) ); for (i=0;i<2;i++) printf ("m[%d]=%d, m1[%d]=%d, b[%d]=%d\n", i, m[i], i, m1[i], i, b[i]); return 0; } [-- Attachment #3: 1.s --] [-- Type: text/plain, Size: 1057 bytes --] .file "1.c" .section .rodata .align 32 .LC0: .string "m[%d]=%d, m1[%d]=%d, b[%d]=%d\n" .text .globl main .type main,@function main: pushl %ebp movl %esp, %ebp subl $40, %esp andl $-16, %esp movl $0, %eax subl %eax, %esp movl $16909060, -8(%ebp) movl $84281096, -4(%ebp) movl $0, -16(%ebp) movl $0, -12(%ebp) leal -8(%ebp), %eax movl %eax, -24(%ebp) leal -16(%ebp), %eax movl %eax, -28(%ebp) movl -24(%ebp), %eax #APP movq (%eax), %mm0 leal -16(%ebp), %eax movq %mm0, (%eax) #NO_APP movl %eax, -28(%ebp) movl $0, -20(%ebp) .L2: cmpl $1, -20(%ebp) jbe .L5 jmp .L3 .L5: subl $4, %esp movl -20(%ebp), %eax pushl -16(%ebp,%eax,4) pushl -20(%ebp) movl -20(%ebp), %eax leal 0(,%eax,4), %edx movl -28(%ebp), %eax pushl (%eax,%edx) pushl -20(%ebp) movl -20(%ebp), %eax leal 0(,%eax,4), %edx movl -24(%ebp), %eax pushl (%eax,%edx) pushl -20(%ebp) pushl $.LC0 call printf addl $32, %esp leal -20(%ebp), %eax incl (%eax) jmp .L2 .L3: movl $0, %eax leave ret .Lfe1: .size main,.Lfe1-main .ident "GCC: (GNU) 3.2.3" ^ permalink raw reply [flat|nested] 4+ messages in thread
* extended asm+pointers
@ 2004-08-11 9:00 Ankit Jain
2004-08-11 10:51 ` sandeep
2004-08-11 18:33 ` Brian Raiter
0 siblings, 2 replies; 4+ messages in thread
From: Ankit Jain @ 2004-08-11 9:00 UTC (permalink / raw)
To: linux-assembly
hi
well i want to understand how assembler treats
pointers?
my code is:
1 #include<inttypes.h>
2
3
4 int main()
5 {
6 uint8_t
a[8]={1,2,3,4,5,6,7,8},b[8]={0,0,0,0,0,0},i;
7 uint8_t *m,*m1;
8
9 m=a;
10 m1=b; //i have pointed m1 to b
11 for(i=0;i<8;i++)
12 printf("%d ",a[i]);
13 printf("\n");
14 asm("movq (%1), %%mm0 \n"
15 "movq %%mm0, (%0) \n"
16 :"=r"(m1)
17 :"r"(m)
18 );
19
20 for(i=0;i<8;i++)
21 printf("%d ",b[i]);
22 return 0;
23 }
well this problem is not solved yet. because when i
display b array then it prints all 0's. according to
me since i have initialised this m1 pointer then by b
then b whould have all the values which i have moved
some have advised me to use arrays here as constraint
but i want to use pointers. i am using r constraint
and it says it says that m1 will use a register (i
guess there is no problem in that)
what is the complete problem HOW THIS ASSEMBLER IS
TREATING THIS POINTER m1?
thanks
ankit jain
________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: extended asm+pointers 2004-08-11 9:00 Ankit Jain @ 2004-08-11 10:51 ` sandeep 2004-08-11 18:33 ` Brian Raiter 1 sibling, 0 replies; 4+ messages in thread From: sandeep @ 2004-08-11 10:51 UTC (permalink / raw) To: Ankit Jain; +Cc: linux-assembly Ankit Jain wrote: > 4 int main() > 5 { > 6 uint8_t > a[8]={1,2,3,4,5,6,7,8},b[8]={0,0,0,0,0,0},i; > 7 uint8_t *m,*m1; > 8 > 9 m=a; > 10 m1=b; //i have pointed m1 to b > 11 for(i=0;i<8;i++) > 12 printf("%d ",a[i]); > 13 printf("\n"); > 14 asm("movq (%1), %%mm0 \n" > 15 "movq %%mm0, (%0) \n" > 16 :"=r"(m1) > 17 :"r"(m) > 18 ); this asm(...) is effectively achieving "m1=m;" you can verify this by printing m1[i] instead of a[i] and b[i] > 19 > 20 for(i=0;i<8;i++) > 21 printf("%d ",b[i]); > 22 return 0; > 23 } > well this problem is not solved yet. because when i > display b array then it prints all 0's. according to > me since i have initialised this m1 pointer then by b > then b whould have all the values which i have moved > > some have advised me to use arrays here as constraint > but i want to use pointers. i am using r constraint > and it says it says that m1 will use a register (i > guess there is no problem in that) -- regards sandeep -------------------------------------------------------------------------- Always borrow money from a pessimist; he doesn't expect to be paid back. -------------------------------------------------------------------------- ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: extended asm+pointers 2004-08-11 9:00 Ankit Jain 2004-08-11 10:51 ` sandeep @ 2004-08-11 18:33 ` Brian Raiter 1 sibling, 0 replies; 4+ messages in thread From: Brian Raiter @ 2004-08-11 18:33 UTC (permalink / raw) To: linux-assembly > 14 asm("movq (%1), %%mm0 \n" > 15 "movq %%mm0, (%0) \n" > 16 :"=r"(m1) > 17 :"r"(m) > 18 ); I believe this code copies the contents of m to m1. (Actually, with movq, I guess it will copy an extra four bytes in the process.) After it runs, both m and m1 will point to b[]. I think part of your problem is that you're trying to treat an array as an lvalue. gcc is decomposing your array into a pointer to the first element, which is not a valid lvalue. So you're trying to do the same thing via pointers. But it's not the same thing at all. In other words, you're stumbling with how C treats arrays and pointers, not the assembler. Get rid of your m and m1 variables, and try doing this instead: asm("movq (%1), %%mm0 \n" "movq %%mm0, (%0) \n" : : "r"(b), "r"(a) ); (Note the lack of output operands. That's because we're not modifying the "pointer" b. We're just modifying the array that b points to.) I think this will do what you want. b ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-08-11 18:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20040811112319.87376.qmail@web52908.mail.yahoo.com>
2004-08-11 13:04 ` extended asm+pointers sandeep
2004-08-11 9:00 Ankit Jain
2004-08-11 10:51 ` sandeep
2004-08-11 18:33 ` Brian Raiter
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).