OSX 64 位上的 NASM 问题 [英] NASM issue on OSX 64-bit

查看:31
本文介绍了OSX 64 位上的 NASM 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 ASM,但遇到了一个小问题.我不能在section.data"中声明"多个字符串.我正在尝试这样的事情:

I'm learning ASM and I have a small problem. I can't "declare" more than one string in "section.data". I'm trying something like this:

section .data
    string1 db "test1 ", 0;
    string2 db "test2 ", 0;
section .text
    global _test
    extern _puts
    _test:
         lea rdi, [rel string1]
         call _puts
         lea rdi, [rel string2]
         call _puts
         ret

这个函数应该在 STDOUT 上打印test1 test2",但它不起作用.结果是:

This function is supposed to print "test1 test2 " on STDOUT, but it doesn't work. The result is:

test2

它只对存储的最后一个字符串有效!如果有人知道原因,请告诉我!

It only works for the last string stored! If someone know why, please tell me!

推荐答案

如果您使用的是 nasm 2.11.08,则会记录一个问题 此处 用于结合数据部分中的多个条目的相对寻址.

If you're using nasm 2.11.08, there is a issue documented here to do with relative addressing combined with multiple entries in the data section.

你可以做两件事中的一件事(或两件事)来确定.

You can do one (or both) of two things to be certain.

首先,您可以查看生成的汇编代码,以调查实际上生成的内容.这可能是最终的选择,因为这样您就可以准确地看到 CPU 将运行的内容.

First, you can have a look at the generated assembler code to investigate what it's actually churning out. That's probably the definitive option since you can then see exactly what the CPU will be running.

其次,您可以使用较早版本的nasm 测试您的代码,看看问题是否会消失.如果是这样,这就是间接证据表明 2.11.08 中的错误导致了您的问题.

Second, you can test your code with an earlier release of nasm to see if the problem goes away. If so, that's indirect evidence that it's the bug in 2.11.08 causing your issues.

这篇关于OSX 64 位上的 NASM 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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