【问题标题】:Why is this coding behaving this way?为什么这个编码会这样?
【发布时间】:2019-07-09 18:44:50
【问题描述】:

下面的代码打印出 3、5、6。你能帮我理解为什么(以及为什么不是 33、35、36?)

                  global_start
                  section .data
00000000 03000000         x: dd 3

00000004 8B0D[00000000]   _start: mov ecx, [x]
0000000A 000D[16000000]   r: add byte [l+6], cl
00000010 C605[00000000]30 l: mov byte [x], 48
00000017 51               push ecx
00000018 B804000000       mov eax, 4 ; For "write" system call
0000001D BB01000000       mov ebx, 1 ; to standard output
00000022 B9[000000000]    mov ecx, x ; "buffer"
00000027 BA01000000       mov edx, 1 ; byte count
0000002C CD80             int 0x80
0000002E 59               pop ecx
0000002F E209             loop r, ecx ; decrement ecx, jump relative if not zero
00000031 BB00000000       mov ebx, 0
00000036 B801000000       mov eax, 1 ; for "exit" system call
0000003B CD80             int 0x80

此代码是用 Assembly 8086 x32bit (NASM LISTING) 编写的。 RAM 使用小印度。

【问题讨论】:

  • 你可能想要global _start

标签: assembly x86 nasm system-calls endianness


【解决方案1】:

我想通了。该代码确实将 33、35、36 存储在 x 中。但是,当“write”系统调用将 x 打印到标准输出时,它会打印这些值表示的字符(在 ascii 中)。由于 HEX 中的 33、35、36 分别是字符 '3'、'5'、'6',那么这就是打印到 stdout 的内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-02
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-15
    • 2013-03-26
    相关资源
    最近更新 更多