首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >gcc真的知道如何输出NASM程序集吗?

gcc真的知道如何输出NASM程序集吗?
EN

Stack Overflow用户
提问于 2011-12-06 12:12:17
回答 1查看 4.5K关注 0票数 3

因此,我有一个简单的C程序,它循环遍历传递给main的args,然后返回:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <stdio.h>

int main(int argc, char *argv[])
{
    int i;
    for(i = 0; i < argc; ++i) {
        fprintf(stdout, "%s\n", argv[i]);
    }
    return 0;
}

我想看看gcc是如何用NASM格式写出这个程序集的。我查看了.asm文件中的输出,注意到语法是TASM。下面是gcc的制作文件和输出。是我做错了什么,还是gcc没有输出真正的NASM语法?

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
all: main

main: main.o
        ld -o main main.o

main.o : main.c
        gcc -S -masm=intel -o main.asm main.c
        nasm -f elf -g -F stabs main.asm -l main.lst

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
    .file   "main.c"
    .intel_syntax noprefix
    .section    .rodata
.LC0:
    .string "%s\n"
    .text
.globl main
    .type   main, @function
main:
    push    ebp
    mov ebp, esp
    and esp, -16
    sub esp, 32
    mov DWORD PTR [esp+28], 0
    jmp .L2
.L3:
    mov eax, DWORD PTR [esp+28]
    sal eax, 2
    add eax, DWORD PTR [ebp+12]
    mov ecx, DWORD PTR [eax]
    mov edx, OFFSET FLAT:.LC0
    mov eax, DWORD PTR stdout
    mov DWORD PTR [esp+8], ecx
    mov DWORD PTR [esp+4], edx
    mov DWORD PTR [esp], eax
    call    fprintf
    add DWORD PTR [esp+28], 1
.L2:
    mov eax, DWORD PTR [esp+28]
    cmp eax, DWORD PTR [ebp+8]
    jl  .L3
    mov eax, 0
    leave
    ret
    .size   main, .-main
    .ident  "GCC: (GNU) 4.5.1 20100924 (Red Hat 4.5.1-4)"
    .section    .note.GNU-stack,"",@progbits

命令行中的错误如下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[mehoggan@fedora sandbox-print_args]$ make
gcc -S -masm=intel -o main.asm main.c
nasm -f elf -g -F stabs main.asm -l main.lst
main.asm:1: error: attempt to define a local label before any non-local labels
main.asm:1: error: parser: instruction expected
main.asm:2: error: attempt to define a local label before any non-local labels
main.asm:2: error: parser: instruction expected
main.asm:3: error: attempt to define a local label before any non-local labels
main.asm:3: error: parser: instruction expected
main.asm:4: error: attempt to define a local label before any non-local labels
main.asm:5: error: attempt to define a local label before any non-local labels
main.asm:5: error: parser: instruction expected
main.asm:6: error: attempt to define a local label before any non-local labels
main.asm:7: error: attempt to define a local label before any non-local labels
main.asm:7: error: parser: instruction expected
main.asm:8: error: attempt to define a local label before any non-local labels
main.asm:8: error: parser: instruction expected
main.asm:14: error: comma, colon or end of line expected
main.asm:17: error: comma, colon or end of line expected
main.asm:19: error: comma, colon or end of line expected
main.asm:20: error: comma, colon or end of line expected
main.asm:21: error: comma, colon or end of line expected
main.asm:22: error: comma, colon or end of line expected
main.asm:23: error: comma, colon or end of line expected
main.asm:24: error: comma, colon or end of line expected
main.asm:25: error: comma, colon or end of line expected
main.asm:27: error: comma, colon or end of line expected
main.asm:29: error: comma, colon or end of line expected
main.asm:30: error: comma, colon or end of line expected
main.asm:35: error: parser: instruction expected
main.asm:36: error: parser: instruction expected
main.asm:37: error: parser: instruction expected
make: *** [main.o] Error 1

让我相信这是TASM语法的是发布在这个链接上的信息:http://rs1.szif.hu/~tomcat/win32/intro.txt

由于

编码缺乏广泛使用的"ptr“关键字,因此它在使用中经常会出现词汇困难。

TASM使用如下:

mov al,字节ptr ds:si或mov ax,word ptr ds:si或mov eax,dword ptr ds:si

对于NASM来说,这只是转化为:

mov al,字节ds:si或mov ax,word ds:si或mov eax,dword ds:si

NASM允许在许多地方使用这些大小的关键字,因此可以以统一的方式控制生成的操作码,例如,这些都是有效的:

推送dword 123 jmp ds: word 1234;它们都指定偏移量jmp ds: dword 1234的大小;用于连接32位段和;16位段时的复杂代码。

它可能会变得毛茸茸的,但重要的是,当你想要它的时候,你可以拥有你所需要的所有控制。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-06 12:56:37

Intel语法意味着Intel语法,而不是NASM语法。MASM和TASM语法是建立在Intel语法基础上的,NASM语法从Intel语法中得到了启发,但它是不同的。

gcc输出的实际上是使用Intel语法对单个指令使用的气体语法(汇编程序指令、标签等)。使用气体专用语法)

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8406188

复制
相关文章
pandas DataFrame的创建方法
在pandas里,DataFrame是最经常用的数据结构,这里总结生成和添加数据的方法: ①、把其他格式的数据整理到DataFrame中; ②在已有的DataFrame中插入N列或者N行。
py3study
2020/01/19
2.6K0
pandas DataFrame的创建方法
Pandas DataFrame笔记
1.属性方式,可以用于列,不能用于行 2.可以用整数切片选择行,但不能用单个整数索引(当索引不是整数时) 3.直接索引可以使用列、列集合,但不能用索引名索引行  用iloc取行,得到的series:
用户1075292
2018/01/23
9740
Pandas DataFrame笔记
Pandas-3. DataFrame
Series组成的字典可以作为参数来创建DataFrame。其索引是所有Series的索引的并集。 例子:
悠扬前奏
2019/05/28
1.2K0
Pandas DataFrame 取整列
使用 df = pd.read_csv("csv_file.csv") 读出来的数据 就是 DataFrame 格式 ? <class 'pandas.core.frame.DataFrame'>
莫听穿林
2022/01/10
1.7K0
Pandas 如何创建 DataFrame
我们已经知道了什么是 Series,在使用 Series 之前,我们得知道如何创建 Series。
用户7886150
2020/12/26
1.6K0
pandas和spark的dataframe互转
由于pandas的方式是单机版的,即toPandas()的方式是单机版的,所以参考breeze_lsw改成分布式版本:
机器学习和大数据挖掘
2019/07/01
2.9K0
(六)Python:Pandas中的DataFrame
        DataFrame与Series相比,除了可以每一个键对应许多值之外,还增加了列索引(columns)这一内容,具体内容如下所示:
小点点
2022/12/12
3.9K0
合并Pandas的DataFrame方法汇总
Pandas是数据分析、机器学习等常用的工具,其中的DataFrame又是最常用的数据类型,对它的操作,不得不熟练。在《跟老齐学Python:数据分析》一书中,对DataFrame对象的各种常用操作都有详细介绍。本文根据书中介绍的内容,并参考其他文献,专门汇总了合并操作的各种方法。
老齐
2021/03/11
5.7K0
python pandas dataframe函数_Python Pandas dataframe.ne()用法及代码示例
Python是进行数据分析的一种出色语言,主要是因为以数据为中心的python软件包具有奇妙的生态系统。 Pandas是其中的一种,使导入和分析数据更加容易。
用户7886150
2021/01/16
1.6K0
使用Pandas melt()重塑DataFrame
重塑 DataFrame 是数据科学中一项重要且必不可少的技能。在本文中,我们将探讨 Pandas Melt() 以及如何使用它进行数据处理。
deephub
2022/01/21
3K0
使用Pandas melt()重塑DataFrame
Pandas DataFrame 数据合并、连接
merge 通过键拼接列 pandas提供了一个类似于关系数据库的连接(join)操作的方法merage,可以根据一个或多个键将不同DataFrame中的行连接起来 语法如下:
马哥Python
2019/06/27
3.4K0
[869]pandas的dataFrame的行列索引操作
这里的index的索引列是从0开始的,那么现在我想要让它从1开始怎么做? 我搜了几篇文章,发现有的是:
周小董
2020/07/21
1.5K0
pandas中的 fillna使用(pandas.DataFrame.fillna)「建议收藏」
3、将“A”、“B”、“C”和“D”列中的所有 NaN 元素分别替换为 0、1、2 和 3。
全栈程序员站长
2022/09/22
3.5K0
pandas中的 fillna使用(pandas.DataFrame.fillna)「建议收藏」
Pandas DataFrame创建方法大全
Pandas是Python的数据分析利器,DataFrame是Pandas进行数据分析的基本结构,可以把DataFrame视为一个二维数据表,每一行都表示一个数据记录。本文将介绍创建Pandas DataFrame的6种方法。
用户1408045
2019/09/17
5.8K0
Pandas DataFrame创建方法大全
Pandas高级教程之:Dataframe的合并
Pandas提供了很多合并Series和Dataframe的强大的功能,通过这些功能可以方便的进行数据分析。本文将会详细讲解如何使用Pandas来合并Series和Dataframe。
子润先生
2021/06/18
2.3K0
Pandas DataFrame的基本属性详解
df = pd.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False) 创建一个DataFrame
全栈程序员站长
2022/08/22
1.3K0
Pandas DataFrame的基本属性详解
如何遍历pandas当中dataframe的行
现在需要遍历上面DataFrame的行。对于每一行,都希望能够通过列名访问对应的元素(单元格中的值)。也就是说,需要类似如下的功能:
马哥Python
2019/06/27
4K0
pandas dataframe的合并(append, merge, concat)
创建2个DataFrame:>>>df1=pd.DataFrame(np.ones((4,4))*1,columns=list('DCBA'),inde
Java架构师必看
2021/12/24
2.9K0
Pandas高级教程之:Dataframe的合并
Pandas提供了很多合并Series和Dataframe的强大的功能,通过这些功能可以方便的进行数据分析。本文将会详细讲解如何使用Pandas来合并Series和Dataframe。
程序那些事
2021/06/14
5.3K0
点击加载更多

相似问题

Pandas Dataframe -速率计算

116

计算Pandas Dataframe的整列

112

从pandas DataFrame计算pvalue

14

从Pandas DataFrame计算IDF

12

Pandas dataframe的群内计算

10
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文