Assembly 带标准输出的x64汇编输出r8d寄存器
我使用x64汇编来创建一个简单的计数器程序。我的目标是让程序遍历从1到10的数字,并使用循环打印出来。我使用r8b来存储我的号码,因为它变化很小,不占用太多存储空间。但我似乎无法用标准打印出数字。我也不能将其中的值更改为更高的值。我在linux上使用nasm汇编代码。Assembly 带标准输出的x64汇编输出r8d寄存器,assembly,64-bit,Assembly,64 Bit,我使用x64汇编来创建一个简单的计数器程序。我的目标是让程序遍历从1到10的数字,并使用循环打印出来。我使用r8b来存储我的号码,因为它变化很小,不占用太多存储空间。但我似乎无法用标准打印出数字。我也不能将其中的值更改为更高的值。我在linux上使用nasm汇编代码。代码如下: section .data section .bss section .text global _start printrcx: mov rax,4 ; Write mov rbx,1 ; Stand
代码如下:
section .data
section .bss
section .text
global _start
printrcx:
mov rax,4 ; Write
mov rbx,1 ; Standard output
int 80h ; Call kernel to run
ret ; Return out of proc
exit:
mov rax,1 ; Exit call
mov rbx,0 ; Code 0
int 80h ; Call kernel to run
ret ; Return if necessary
counter:
push rcx
mov rcx,r8b ; Number
mov rdx,2 ; 2 in length
call printrcx
cmp r8b, 10 ; Check if counter is at 10
je exit ; Exit if counter is at 10
add r8b, 1 ; Add 1 to the counter
jmp counter ; If previous passed then
; jump back to counter
_start:
mov r8b,1 ; Set counter to 1
jmp counter ; Start counter
call exit
阅读相关的ABI文档(本例中为SysV x86-64)。您会注意到,不应该对系统调用使用
int0x80
。另外,r8
是呼叫者保存的。如果要打印它,还需要将其转换为文本。“$man 2系统调用”x86_64 rdi rsi rdx r10 r8 r9-x86_64系统调用rax rax请参阅below@EOF:在使用IA32int 0x80
仿真的情况下(假设它在Linux内核中启用)在64位代码中,内核将在int0x80
@EOF中保留除RAX之外的所有寄存器。如果im不打算使用int0x80,我该怎么办