gpt4 book ai didi

linux - NASM Linux 程序集打印整数

转载 作者:IT王子 更新时间:2023-10-29 00:43:54 25 4
gpt4 key购买 nike

我正在尝试在 Linux 上的 nasm 程序集中打印一位整数。我目前编译的内容很好,但没有任何内容被写入屏幕。谁能向我解释我在这里做错了什么?

section .text
global _start

_start:
mov ecx, 1 ; stores 1 in rcx
add edx, ecx ; stores ecx in edx
add edx, 30h ; gets the ascii value in edx
mov ecx, edx ; ascii value is now in ecx
jmp write ; jumps to write


write:
mov eax, ecx ; moves ecx to eax for writing
mov eax, 4 ; sys call for write
mov ebx, 1 ; stdout

int 80h ; call kernel
mov eax,1 ; system exit
mov ebx,0 ; exit 0
int 80h ; call the kernel again

最佳答案

这是添加,不是存储:

add edx, ecx        ; stores ecx in edx

这会将 ecx 复制到 eax,然后用 4 覆盖它:

mov eax, ecx        ; moves ecx to eax for writing
mov eax, 4 ; sys call for write

编辑:

对于“写”系统调用:

eax = 4
ebx = file descriptor (1 = screen)
ecx = address of string
edx = length of string

关于linux - NASM Linux 程序集打印整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6903435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com