我最近开始用汇编语言编程,可能会出错。这段代码应该写出“21947392”:
Starting program: /home/anwesh/Documents/NS2/LAB/prog5/a.out
> enter the number of nodes in the network... 5
> distance vector table for node A
Program received signal SIGSEGV, Segmentation fault.
0x000055555555487e in main ()
(gdb)
它是在NASM上为macOS x64编写的,它只打印“2”(似乎甚至从一个程序集到另一个程序集)...... 以下是我在终端中使用的命令:
section .data
nl db 10
section .bss
number resb 19
.end resb 1
section .text
GLOBAL start
start:
mov rdi, 21947392
call _printNumber
mov rax, 0x2000001
xor rdi, rdi
syscall
_printNumber:
mov rcx, 10
mov rsi, number.end
mov rax, rdi
_loop:
xor rdx, rdx
div rcx
add rdx, 48
mov [rsi], rdx
dec rsi
cmp rax, 0
jne _loop
mov rdi, rsi
inc rdi
mov rsi, number.end
sub rsi, rdi
call _print
mov rdi, nl
mov rsi, 1
call _print
ret
_print:
mov rax, 0x2000004
mov rdx, rsi
mov rsi, rdi
mov rdi, 1
syscall
ret
请帮助找出错误。