0

我用 Gnu 管理了“Hello World”!

那么,接下来是打印 1 到 10 对吗?(也许在红宝石中)

目前,我很乐意打印 A,紧随其后的是 B。这就是我所拥有的。

.section .text
  .globl _start

_start:
  # Print A
  movl  $4,%eax
  pushl $0x41
  movl  %esp,%ecx        # Would rather movl $0x41,%ecx
  movl  $1,%ebx
  movl  $1,%edx
  int   $0x80

  # Closely followed by B
  movl  $4,%eax
  incl  (%esp)           # Rather incl(%ecx) here
  movl  %esp,%ecx
  movl  $1,%ebx
  movl  $1,%edx
  int   $0x80

  movl  $1,%eax
  movl  $0,%ebx
  int   $0x80

它确实有效,但我的问题是,为什么我不能

  movl  $0x41,%ecx

开始,然后

  incl (%ecx)

稍后?

4

1 回答 1

0

对于 sys_write,%ecx 想要指向一个或多个字符在内存中的位置,而不是“成为”要打印的字符。"incb" 可能比 "incl" 更正确,因为你只增加一个字节 - "(%esp)" 或 "(%ecx)" 应该可以工作,因为此时它们指向同一个地方。请注意,您正在增加内存的“内容”,而不是指向内存的指针。

最好的,弗兰克

于 2012-07-17T03:05:52.813 回答