1 //----------------------------------------------------------------- 2 // linuxapp.s 3 // 4 // This is a simple Linux application-program, written in the 5 // GNU assembly language, for execution by an ia32 processor. 6 // 7 // to assemble: $ as --32 linuxapp.s -o linuxapp.o 8 // and to link: $ ld -melf_i386 linuxapp.o -o linuxapp 9 // and execute: $ ./linuxapp 10 // 11 // NOTE: Our classroom systems now produce x86_64 executables 12 // by default, unless we override with command-line switches. 13 // 14 // programmer: ALLAN CRUSE 15 // written on: 15 OCT 2008 16 //----------------------------------------------------------------- 17 18 19 # manifest constants 20 .equ sys_EXIT, 1 # ID-number for 'exit' 21 .equ sys_WRITE, 4 # ID-number for 'write' 22 .equ dev_STDOUT, 1 # ID-number for STDOUT 23 24 25 .section .data 26 0000 0A204865 msg: .ascii "\n Hello, world! \n\n" # contents of message 26 6C6C6F2C 26 20776F72 26 6C642120 26 0A0A 27 0012 12000000 len: .int . - msg # count of characters 28 29 30 .section .text 31 _start: 32 # display message 33 0000 B8040000 mov $sys_WRITE, %eax # system-call ID-number 33 00 34 0005 BB010000 mov $dev_STDOUT, %ebx # device-file ID-number 34 00 35 000a 8D0D0000 lea msg, %ecx # address of the string 35 0000 36 0010 8B151200 mov len, %edx # length of the message 36 0000 37 0016 CD80 int $0x80 # invoke kernel service 38 39 # terminate application 40 0018 B8010000 mov $sys_EXIT, %eax # system-call ID-number 40 00 41 001d BB000000 mov $0, %ebx # program's exit-status 41 00 42 0022 CD80 int $0x80 # invoke kernel service 43 44 .global _start # make entry-point visible 45 .end # nothing more to assemble