How to declare and initialize local variables in gcc inline assembly without extended inline asm?

孤人 提交于 2021-02-18 12:20:14

问题


I know this is a very basic question but I am really stuck on it. In fact I am absolutely newbie in GCC syntax.

I want to have local variables (Stack addresses with labels) without using extended inline assembly. Something like the following code in Intel syntax:

DATA1  DB  100 
MOV AL, DATA1

This is the code I guess may substitute in GCC:

int someFunction(int x)
{
    __asm__ volatile(
                     "function1:"
                     ".data;"
                     ".2byte $4 data1   ;"

                     ".text;"
                     "pushq %rbp;"
                     "movq %rsp , %rbp ;"

                     "movl var , %eax;"  // this is source of error

                     "popq %rbp;"
                     "leaveq;"
                     "retq ; "
                    ); 
}

But this code results in this error:

symbol(s) not found for architecture x86_64

I can use global variables in x86 but the same result comes in x64 or x86_x64.

Setting: LLVM 4.1; Cocoa used in Xcode 4

What is the correct syntax?


回答1:


GCC inline assembler doesn't support local variables, use GCC's extended syntax.

If you are uncomfortable with AT&T syntax there are ways to use Intel syntax on GCC.

This is an excellent how-to on GCC asm.



来源:https://stackoverflow.com/questions/14155046/how-to-declare-and-initialize-local-variables-in-gcc-inline-assembly-without-ext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!