English 中文(简体)
Error在试图在乌兰巴乌托的NAM上操作案卷
原标题:Error when trying to run .asm file on NASM on Ubuntu

I m using ubuntu 64-bit and trying to run a .asm file on NASM. But it returns this error when I try to run the following code. What Iḿ trying to do is build an executable by compiling (or assembling) object file from the source $ nasm -f elf hello.asm, and then after created the file hello.o is producing executable file itself from the object file by invoking linker

$ ld -s -o hello hello.o

这将最终形成可起诉的 h。

http://www.faqs.org/docs/HCH-HOWTO/Assembly-HOWTO.html” rel=“noretinger” http://www.faqs.org/docs/HCH-HOWTO/Assembly-HOWTO.html。

http://www.ohchr.org。

i386 投入文件“hello.o”的结构与I386:x86-64的产出不符

<><>Code>:

     section .data              ;section declaration

 msg     db      "Hello, world!",0xa    ;our dear string
 len     equ     $ - msg                 ;length of our dear string

 section .text              ;section declaration

             ;we must export the entry point to the ELF linker or
     global _start       ;loader. They conventionally recognize _start as their
             ;entry point. Use ld -e foo to override the default.

 _start:

 ;write our string to stdout

         mov     edx,len ;third argument: message length
         mov     ecx,msg ;second argument: pointer to message to write
         mov     ebx,1   ;first argument: file handle (stdout)
         mov     eax,4   ;system call number (sys_write)
         int     0x80   ;call kernel

  ;and exit

     mov    ebx,0   ;first syscall argument: exit code
         mov     eax,1   ;system call number (sys_exit)
         int     0x80   ;call kernel
最佳回答

看来,在<代码>nasm和<代码><<>ld/code>试图做到:

i386 architecture of input file  hello.o  is incompatible with i386:x86-64 output

换言之,nasm生成了32个轨道物体文档hello.old希望采取这一办法,并提出64个可执行的文件。

<代码>nasm -hf 指挥应当给你现有的产出格式:

valid output formats for -f are (`*  denotes default):
  * bin       flat-form binary files (e.g. DOS .COM, .SYS)
    ith       Intel hex
    srec      Motorola S-records
    aout      Linux a.out object files
    aoutb     NetBSD/FreeBSD a.out object files
    coff      COFF (i386) object files (e.g. DJGPP for DOS)
    elf32     ELF32 (i386) object files (e.g. Linux)
    elf       ELF (short name for ELF32) 
    elf64     ELF64 (x86_64) object files (e.g. Linux)
    as86      Linux as86 (bin86 version 0.3) object files
    obj       MS-DOS 16-bit/32-bit OMF object files
    win32     Microsoft Win32 (i386) object files
    win64     Microsoft Win64 (x86-64) object files
    rdf       Relocatable Dynamic Object File Format v2.0
    ieee      IEEE-695 (LADsoft variant) object file format
    macho32   NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files
    macho     MACHO (short name for MACHO32)
    macho64   NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files
    dbg       Trace of all info passed to output stage

I see that your linked tutorial asks you to run:

nasm -f elf hello.asm

使用:

nasm -f elf64 hello.asm

相反,你可以找到<代码>ld。 停止投诉投入文件。

问题回答

你们需要告诉联系人,以编制一份I386份产出文件,因为你重新撰写了I386份文件:

ld -m elf_i386 -s -o hello hello.o

How to compile, link, and run a nasm app on Ubuntu 64 bit.

<>Install nasm:

sudo apt-get install nasm

<Save a file with filename hello.asm:

section .data
  hello:     db  Hello world! ,10    ;  Hello world!  plus a linefeed character
  helloLen:  equ $-hello             ; Length of the  Hello world!  string
                                     ; (I ll explain soon)

section .text
  global _start

_start:
  mov eax,4            ; The system call for write (sys_write)
  mov ebx,1            ; File descriptor 1 - standard output
  mov ecx,hello        ; Put the offset of hello in ecx
  mov edx,helloLen     ; helloLen is a constant, so we don t need to say
                       ;  mov edx,[helloLen] to get it s actual value
  int 80h              ; Call the kernel

  mov eax,1            ; The system call for exit (sys_exit)
  mov ebx,0            ; Exit with return code of 0 (no error)
  int 80h

www.un.org/Depts/DGACM/index_spanish.htm Compile it:

nasm -f elf64 hello.asm

<Link:

ld -s -o hello hello.o

www.un.org/Depts/DGACM/index_spanish.htm 页: 1

el@apollo:~$ ./hello
Hello world!

www.un.org/Depts/DGACM/index_spanish.htm 它发挥作用! 现在是什么? 要求贵方编辑制作通常通过成机代码的大会代码。 谷歌搜索:“构造”

<>Perspective: 如今,所有的人都试图冲淡和为公众取走通用计算方法,因此,我们必须向新学生教授如何从核心原则上建立通用机器的概念,用光金属,最后是集聚器和节目制作语言。

How does learning assembly aid in programming? 99% of computer programs out there are 10 to 100 times slower than they could optimized to be only because programmers don t know what delays are being forced on them by their favorite high level compiler or interpreter.

彻底了解这里的全部内容意味着,你可以强迫您的方案,使那些仅用纳米镜头来做手头工作的财产受到审查。 时间=金钱。 因此,这种了解如何抹去那些需要比几个纳米秒长才能完成节省时间、因此需要钱的东西。

> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >< > > > > > >< > > > > > > > > > > > > > > > > > > > > > > > >





相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签