我可以使用系統調用寫入打印內存中的一些數據到STDOUT:如何將RAX中的值寫入彙編中的STDOUT?
ssize_t write(int fd, const void *buf, size_t count);
即:
movq $1, %rax
movq $1, %rdi
move address_of_variable %rsi
movq $5, %rdx
syscall
但我怎麼能打印寄存器的值?
UPDATE
.text
call start
start:
movq $100, %rdi
movq $10, %rsi
call print_number
ret
buffer:
.skip 64
bufferend:
# rdi = number
# rsi = base
print_number:
leaq bufferend, %rcx
movq %rdi, %rax
1:
xorq %rdx, %rdx
divq %rsi
add $'0', %dl
cmp $'9', %dl
jbe 2f
add $'A'-'0'-10, %dl
2:
sub $1, %rcx
mov %dl, (%rcx)
and %rax, %rax
jnz 1b
mov %rcx, %rsi
lea bufferend, %rdx
sub %rcx, %rdx
movq $1, %rax
movq $1, %rdi
syscall
ret
http://stackoverflow.com/questions/7087020/outputting-registers-to-the-console-with-masm/7088064#7088064 –