[LLVMdev] need help understanding getelementptr assembler instruction

Robert Mykland robert at ascenium.com
Mon Nov 13 11:23:33 PST 2006


Ram:

Let me explain and hopefully Reid or Chris will correct if I have it 
wrong.  The first 0 is the index into a possible array of sbyte[13] 
arrays that this pointer points to.  I expect GetElementPtr works this 
way is to keep down the proliferation of arrays of arrays in the type 
table.  So you are pointing at the zeroth, and in this case only, array 
of sbyte[13].  The next 0 actually indexes into the array of sbyte, so 
you are pointing at index 0, or pointing at the 'H' in "Hello World".

Hope this helps,

-- Robert.

Ram Bhamidipaty wrote:
> I am trying to understand the hello word assember example. This is
> my version:
>
> %str1 = internal constant [13 x sbyte] c"Hello World\0a\00"
>
> declare int %printf(sbyte*, ...)
>
> implementation   ; Functions:
>
> int %main() {
>   %str2 = getelementptr [13 x sbyte]* %str1, long 0, long 0
>   call int(sbyte*, ...) *%printf(sbyte* %str2)
>   ret int 0
> }
>
> Why is getelementptr being given two "long 0" indices?
>
> Thanks for any help.
> -Ram
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
>   



More information about the llvm-dev mailing list