English 中文(简体)
编组代码出乎意料的印刷。
原标题:assembly code unexpectedly printing .shstrtab.text.data

i am very new to assembly although i have lots of c and c++ experience. my assembly code is supposed to print hello world like all first programs in a new language. it prints out hello world but also prints out some extra text:

hello world!
.shstrtab.text.data

我的集会方案:

section .text
    global _start       ;for the linker
    
_start:
    mov edx, length     ; message length
    mov ecx, message    ; message to write
    mov ebx, 1      ; file descriptor stdout
    mov eax, 4      ; system call number
    int 0x80    ; call kernel
    
    mov eax, 1  ;system call number for sys_exit to exit program
    int 0x80    ; call kernel
    
section .data
message db "hello world!"
length DD 10

if you know how to fix this also explain why is this happening. thanks.

extra info: i am using nasm assembler with ld linker

问题回答

因此,问题在于增加篇幅,因为它能够处理长度变量,而不是价值。 回答是使用<条码>除代号,[宽]。 感谢杰斯特指出:

长度(美元)——信息——时间长度(10天)

我给你正确的法典并作解释。 然而,我没有经验告诉你,你的法典为什么不工作。

这里正确的法典:

section .text
    global _start       ;for the linker
    
_start:
    mov edx, length     ; message length
    mov ecx, message    ; message to write
    mov ebx, 1      ; file descriptor stdout
    mov eax, 4      ; system call number
    int 0x80    ; call kernel
    
    mov eax, 1  ;system call number for sys_exit to exit program
    int 0x80    ; call kernel
    
section .data
message db "hello world!"
length equ $-message

在<代码>mesage db “hello universe/code>-<<>>>上,是贴上“hello world>起始地址的标签。

<代码>db系指define byte,用于为标签message分配1个按位次位。

www.un.org/Depts/DGACM/index_spanish.htm TWO VERY CRUCIALTHINGS TO REMEMBER:

  1. Instructions are fetched, decoded and executed 1 AFTER ANOTHER.
  2. Data and Instructions are stored in the same memory.

这就是说,每一封“世界”信都写进了1 AFTER ANOTHER

页: 1

接着,请上<<>tong>next memory Address,该length equ message

In length equ $-message - The $ represents the current address. So, you are subtracting the start of string (message) from end of string ($).

这给你留下了长处,甚至不必人工计算或写。

我在你的法典中发现了一个错误,你写道:length DD 10。 如今,<代码>length 本应保持<代码>message的长度。

然而,<代码>hello World!12 not 10. 另一件事是<条码>d,意思是<条码>define Double , 通常为4英明,储存时间所需的记忆空间要多得多。 您可参考指南

我希望这一帮助,有一天?





相关问题
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 ...

热门标签