如何在不扩展内联汇编的情况下在GCC内联汇编中声明和初始化局部变量? [英] How to declare and initialize local variables in gcc inline assembly without extended inline asm?

查看:66
本文介绍了如何在不扩展内联汇编的情况下在GCC内联汇编中声明和初始化局部变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个非常基本的问题,但我确实坚持了下来.实际上,我绝对是GCC语法的新手.

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

我想使用不带扩展内联汇编的局部变量(带有标签的堆栈地址).类似于Intel语法中的以下代码:

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

这是我想可以在GCC中替换的代码:

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:

架构x86_64找不到

符号

symbol(s) not found for architecture x86_64

我可以在x86中使用全局变量,但在x64或x86_x64中也可以得到相同的结果.

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

设置:LLVM 4.1;Xcode 4中使用的可可粉

Setting: LLVM 4.1; Cocoa used in Xcode 4

正确的语法是什么?

推荐答案

GCC内联汇编器不支持局部变量,请使用

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

如果您对AT& T语法不满意,可以使用

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

这是出色的关于GCC组件的操作方法.

这篇关于如何在不扩展内联汇编的情况下在GCC内联汇编中声明和初始化局部变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆