我正在使用x64程序集来创建一个简单的计数器程序。我的目标是让程序通过1到10的数字并使用循环打印出来。我使用r8b存储我的号码,因为它只是变小而且不占用太多存储空间。但我似乎无法用stdout打印出数字。我也不能将其中的值更改为更高的值。我在linux上使用nasm来汇编代码。
代码如下:
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