When I try and assemble the program, I get a bunch of the following error messages:
misha@hp-laptop:~/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
Can anybody please tell me what exactly I'm doing wrong that my program won't run? Obviously, it's something that has to do with the way I'm trying to get access to the array elements each of which is one byte long. Here's the program itself:
/******************************************************************************
* *
* 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
*/