assembly 从友好的UI(Emu8086)到真实的x86组装

6xfqseft  于 4个月前  发布在  其他
关注(0)|答案(1)|浏览(62)

我是emu 8086模拟器汇编的Maven(这是我们在大学里教的),但显然emu 8086模拟器不是真实的汇编语言,我试图学习x86汇编语言。
我使用this online compiler作为我的学习工具。
我找到了x86微处理器的系统调用:
https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md#x86-32_bit
因为我还是个新手所以我会一直开着它
emu8086我熟悉一般和特殊用途寄存器,虽然名称有点不同,我仍然可以留在道路上。
我正在尝试打印一个32位整数
我注意到,对于eax寄存器的每个值,都有一个不同的系统调用,所以我们不能使用eax在那里执行操作。
ebx寄存器需要设置为1,因为我的唯一输出是1值。
在Chromium OS中,该值由ecx寄存器设置,edx给出ecx寄存器的操作数大小。
我写下了这段代码:

section .data
    hello:     db 'Hello, World!',10    ; 'Hello, World!' plus a linefeed character
    helloLen:  equ $-hello             ; Length of the 'Hello world!' string

section .text
    global _start

_start:
    mov eax,4            
    mov ebx,1
    mov ecx,1
    mov edx,16
    
                         
    int 0x80

字符串
(显然我没有使用.data部分中的任何变量)
我想打印出来1.我设置ecx为1和edx为16,因为整数有16位。但是什么都没有打印出来!我做错了什么?

7gyucuyw

7gyucuyw1#

在您提供的链接中,“write”系统调用名称需要以下参数:

  • ebx -> unsigned int fd
  • ecx -> buffer
  • edx -> count

问题是buffer参数。您将buffer移到1,将count移到16,但char*的大小为4(x86)和8(x64),而且count必须是包括LF的字符串长度。
你应该有一个指针,例如hello,并正常退出,如果没有,它将无限运行。
代码:

section .data
    hello:     db '1',10
    helloLen:  equ $ - hello

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;

字符串

相关问题