NASM 2行的db(初始化数据)似乎不起作用 [英] NASM 2 lines of db (initialized data) seemingly not working

查看:135
本文介绍了NASM 2行的db(初始化数据)似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下x86-64代码,可以在OSX Yosemite上运行:

I have the following x86-64 code, which I can run on OSX Yosemite:

global _main
extern _exit
extern _puts

DEFAULT REL

section .data

putsmsg:    db      'Puts message...',0
another:    db      0

section .text

_main:
    push        rbp
    mov         rbp, rsp

    ; print a string using PUTS
    lea         rdi, [putsmsg]
    call        _puts

    ; call EXIT(0) c function
    mov         rdi, 0
    call        _exit

我按如下所示进行编译,链接和运行(其中源是a.asm):

I compile, link, and run as follows (where the source is a.asm):

nasm -f macho64 a.asm ; gcc a.o -o a.bin ;./a.bin

它不会打印消息"Puts message ...",但是如果我简单地注释掉包含标签"another"的行,它将打印消息.这是怎么了?当我有另一条初始化的数据行时,为什么它不打印正确的字符串?

It does not print the message 'Puts message...', whereas it does print the message if I simply comment out the line containing the label 'another'. What is going wrong here? Why doesn't it print the correct string when I have the other initialized data line?

推荐答案

使用yasm在GNU/Linux上为我工作. (从函数名称中删除_前缀之后.)

Works for me on GNU/Linux, with yasm. (After removing the _ prefix from function names.)

$ yasm -felf64 puts.asm
$ gcc -o put puts.o
$ ./puts
Puts message...

第二个db行仍然存在:

That's with the 2nd db line still present:

another:    db      0

在过去的几周内,关于OS X上的这个问题(当字符串后有更多数据时,消息不打印)几乎完全存在另一个问题.该问题的OP发现OS X上的Yasm对他有效.也许OS X的nasm中存在错误?

There was another question about almost exactly this problem (a message not printing when there was more data following the string) on OS X, within the past couple weeks. The OP of that question found that yasm on OS X worked for him. Maybe there's a bug in nasm for OS X?

我最终找到了我正在谈论的帖子:位置独立代码指向错误的地址.请参阅我对答案的评论中的讨论. OP发现他的代码可以使用yasm,但是无法确定nasm中是否有错误,或者他是否使用错误.

I eventually found the post I was talking about: Position Independent Code pointing to wrong address. See the discussion in comments on my answer. The OP found his code worked with yasm, but wasn't able to tell if there was a bug in nasm or if he was just using it wrong.

这篇关于NASM 2行的db(初始化数据)似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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