Wenn ich versuche, und das Programm zusammenstellen, erhalte ich ein paar der folgenden Fehlermeldungen:Junk `(0,1,1)‘ nach der Expression
[email protected]:~/test$ as -gstabs test.s -o test.o && ld test.o -o a.out && rm test.o && ./a.out
test.s: Assembler messages:
test.s:19: Error: junk `(0,0,1)' after expression
test.s:20: Error: junk `(0,1,1)' after expression
test.s:21: Error: junk `(0,2,1)' after expression
test.s:22: Error: junk `(0,3,1)' after expression
Kann jemand bitte sagen Sie mir, was genau ich bin falsch machen, dass mein Programm nicht läuft? Offensichtlich hat das etwas damit zu tun, wie ich auf die Array-Elemente zugreifen kann, von denen jedes ein Byte lang ist. Hier ist das Programm selbst:
/******************************************************************************
* *
* 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
*/
Ich würde vorschlagen, Ihre handschriftliche Asm-Quelle in einem '.S', nicht einem' .s' zu halten. 'gcc -S test.c' wird ohne zu fragen" test.s "clobber, aber nichts verwendet standardmäßig' .S' als Ausgabedateierweiterung. Alle asm-Quelldateien von glibc sind zum Beispiel '.S'. Sie können auch leicht mit 'gcc -m32 -nostdlib test.S' kompilieren. –
Ihr Laptop läuft hoffentlich nicht mit 32-Bit-Linux, Sie benötigen also "-m32", um 32-Bit-Code auszuführen. Dieser Code könnte tatsächlich im 64bit-Modus funktionieren, da der "int 0x80" ABI noch verfügbar ist, aber sobald Sie '% esp' anstelle von'% rsp' ändern, sind Sie geschraubt. Siehe [diese Antwort zur Erstellung eines 32-Bit-Codes auf einem 64-Bit-System] (http://stackoverflow.com/questions/36861903/assembling-32-bit-binaries-on-a-64-bit-system-gnu-toolchain/36901649 # 36901649) und andere Links im [x86-Tag-Wiki] (http://stackoverflow.com/tags/x86/info) –