【问题标题】:to print to console --> ambuiguity for contents in ecx and edx registers打印到控制台 --> ecx 和 edx 寄存器中的内容的模糊性
【发布时间】:2016-06-04 02:03:32
【问题描述】:

来自我之前的疑问 - Difference between “mov eax, [num]” and “mov eax, num”

我知道“mov eax, num”将num的地址存储在eax中,“mov eax, [num]”将num的值存储在eax中

现在在这里!

    mov     edx, strLen     ; Arg three: the length of the string
    mov     ecx, str        ; Arg two: the address of the string
    mov     ebx, 1          ; Arg one: file descriptor, in this case stdout
    mov     eax, 4          ; Syscall number, in this case the write(2)  

    int     0x80            ; Interrupt 0x80   

section .data     
    str:     db 'Hello, world!',0xA
    strLen:  equ $-str

理想的edx寄存器应该有长度,所以

  • as " mov ecx, str " - 将 str 的地址 存储在 ecx 中
  • 没有“mov edx, strlen”也应该存储strlen的地址而不是edx中的值。
  • 在edx中存储strlen的值,为什么不使用“mov edx, [strlen]

以下代码引用自此链接 - http://asm.sourceforge.net/intro/hello.html

它杀了我!

在此先感谢...

【问题讨论】:

  • 是 .data 部分中的声明,而不是 .bss 部分中的声明与我的问题有任何关系! PS:我知道 .data 部分用于声明常量,而 .bss 部分用于声明变量。
  • "mov eax, [num] " 将值 of num in eax" 可能更准确地表述为 "mov eax, [num] " 将值 at num in eax" 存储值,这可能就是您的意思。
  • @lurker 是的,Lurker 就是我的意思

标签: assembly nasm inline-assembly


【解决方案1】:

strLen 是一个等式 (strLen: equ $-str)。所以发生的只是编译时从mov edx, strLenmov edx, 14 的文本替换。

在这里使用括号是不正确的,因为这会给你mov edx, [14],这不是你想要做的。

(参见 NASM 手册中的 3.2.4 EQU:定义常量部分)

【讨论】:

  • @Micheal 嘿 Micheal 谢谢你,但是关注一下怎么样!下面的“file_name”不是等价部分 .data file_name db 'myfile.txt' section .text mov eax, 8 mov ebx, file_name mov ecx, 0777 int 0x80
  • 你正在加载file_name的地址,正如你所链接的问题所解释的那样。
猜你喜欢
  • 1970-01-01
  • 2016-07-20
  • 2021-03-29
  • 1970-01-01
  • 1970-01-01
  • 2015-03-16
  • 2017-07-30
  • 1970-01-01
  • 2015-06-25
相关资源
最近更新 更多