【发布时间】:2015-07-24 15:00:49
【问题描述】:
在这段代码中,我设法用系统调用打印了一个数组:
%include 'syscalls32.inc'
section .bss
section .data
array dd 1,2,3,4,5
arraylen equ ($ - array) / 4 ; array length * 4 = number of elements
section .text
global _start:
_start:
mov esi, 0 ; get pointer to array
mov edi, arraylen - 1 ; edi = number of array elements
.PrintArray:
mov edx, 1 ; print 1 byte
mov ecx, [array + 4] ; get current array element
add ecx, 48 ; add 48 to convet to ASCII
push ecx ; push to stack since we need an address of item to print
mov ecx, esp ; mov address of char to ecx
mov ebx, stdout
mov eax, sys_write
int 80h ; now print it
pop ecx ; balance stack
add esi, 4 ; get next element, 4 because it's an array of dwords
dec edi ; decrease loop counter
jns .PrintArray ; if edi ! -1 continue loop
.PrintLineFeed:
sub esp, 4
mov byte [esp], 10
mov edx, 1
mov ecx, esp
mov ebx, stdout
mov eax, sys_write
int 80h
add esp, 4 ; not needed since next call is exit, but learn good techniques.
exit:
mov ebx, 0
mov eax, sys_exit
int 80H
我发现了这个 grep 技巧来制作syscalls32.inc:
grep __NR /usr/include/asm/unistd_32.h | grep define | sed -e 's/\#/\%/' -e 's/__NR_/sys_/' > syscalls32.inc
我怎么能做这样的事情来制作像std.inc这样的东西,因为现在我的代码有这个错误:symbol stdout undefined?
顺便说一句,如果我在 .data 部分中将 stdout 设置为 0:stdout equ 0 它工作正常。但我想知道包含文件是否存在或是否可以制作?
【问题讨论】: