후에, 나는 다음과 같은 오류 메시지가 무리를 얻을 수 내 프로그램이 돌아 가지 않을 것이라고 잘못 생각한거야? 당연히, 그것은 각각 제가 1 바이트 길이 인 배열 요소에 접근하려고하는 것과 관련이 있습니다. 다음은 프로그램 자체입니다.정크`(0,1,1) '표현
/******************************************************************************
* *
* This program prints the string "foo" on the console. *
* *
******************************************************************************/
.section .data
array: .byte 0x00, 0x00, 0x00, 0x00 # An array of four bytes
size: .int 4 # The size of the array
.section .text
.globl _start
_start:
movb $0x66, %ah # 66 is the hexadecimal value for 'f'
movb $0x6F, %al # 6F is the hexadecimal value for 'o'
movb $0x6F, %bh # 6F is the hexadecimal value for 'o'
movb $0x0A, %bl # A is the hexadecimal value for '\n'
movb %ah, array(0, 0, 1)
movb %al, array(0, 1, 1)
movb %bh, array(0, 2, 1)
movb %bl, array(0, 3, 1)
# print
movl $4, %eax # 4 is the number for the write system call
movl $1, %ebx # The file descriptor to write to (1 - STDOUT)
movl $array, %ecx # The starting address of the string to print
movl size, %edx # The number of bytes to print
int $0x80 # Wake up the kernel to run the write system call
# exit
movl $1, %eax # 1 is the number for the exit system call
movl $0, %ebx # Exit status code (echo $?)
int $0x80 # Wake up the kernel to run the exit system call
/*
Compile and run:
as -gstabs test.s -o test.o && \
ld test.o -o a.out && \
rm test.o && \
./a.out
*/
필자는 손으로 작성한 asm 소스를'.s'가 아닌'.S' 파일로 유지할 것을 제안합니다. 'gcc -S test.c'는 묻지 않고'test.s'를 혼란에 빠뜨릴 것입니다. 그러나'.S'를 기본값으로 출력 파일 확장자로 사용하는 파일은 없습니다. glibc의 asm 소스 파일은 모두'.S'입니다. 또한'gcc -m32 -nostdlib test.S'로 쉽게 컴파일 할 수 있습니다. –
랩탑 컴퓨터에 32 비트 리눅스가 설치되지 않았으므로 32 비트 코드를 실행하려면'-m32'가 필요합니다. 이 코드는'int 0x80' ABI가 여전히 사용 가능하기 때문에 실제로 64 비트 모드에서 작동하지만,'% rsp' 대신에'% esp'를 수정하자마자 엉망입니다. [이 대답은 64 비트 시스템에서 32 비트 코드 작성하기] 참조 (http://stackoverflow.com/questions/36861903/assembling-32-bit-binaries-on-a-64-bit-system-gnu-toolchain/36901649). # 36901649) 및 [x86 태그 위키]의 다른 링크 (http://stackoverflow.com/tags/x86/info) –