//----------------------------------------------------------------- // usingbss.s // // This Linux application is created for testing the way the // uninitialized data section (named '.bss') will be handled // by the 'default' GNU linker-scipt, and by our 'elfexec.s' // program-loader. (The file-format used here is 'Elf_32'.) // // to assemble: $ as --32 usingbss.s -o usingbss.o // and to link: $ ld -melf_i386 usingbss.o -o usingbss // and install: $ dd if=usingbss of=/dev/sda4 seek=65 // // programmer: ALLAN CRUSE // written on: 06 NOV 2008 //----------------------------------------------------------------- # manifest constants .equ sys_EXIT, 1 # system-call ID-number .equ sys_WRITE, 4 # system-call ID-number .equ dev_STDOUT, 1 # device-file ID-number .section .data hex: .ascii "0123456789ABCDEF" # table of hex numerals leg: .ascii "CR0=" # legend for the output eoi: .ascii "\n" # newline control-code .section .bss buf: .space 8 # uninitialized buffer .section .text #------------------------------------------------------------------ eax2hex: # converts value in EAX to a hexadecimal string at DS:EDI pushal mov $8, %ecx nxnyb: rol $4, %eax mov %al, %bl and $0x0F, %ebx mov hex(%ebx), %dl mov %dl, (%edi) inc %edi loop nxnyb popal ret #------------------------------------------------------------------ _start: # write legend mov $sys_WRITE, %eax # system-call ID-number mov $dev_STDOUT, %ebx # device-file ID-number lea leg, %ecx # address of buffer mov $4, %edx # length of buffer int $0x80 # invoke kernel service # format contents of register CR0 (obtained using 'smsw') smsw %eax # load value from CR0 lea buf, %edi # point DS:EDI to buffer call eax2hex # convert binary to ascii # write buffer mov $sys_WRITE, %eax # system-call ID-number mov $dev_STDOUT, %ebx # device-file ID-number lea buf, %ecx # address of buffer mov $8, %edx # length of buffer int $0x80 # invoke kernel service # write newline mov $sys_WRITE, %eax # system-call ID-number mov $dev_STDOUT, %ebx # device-file ID-number lea eoi, %ecx # address of buffer mov $1, %edx # length of buffer int $0x80 # invoke kernel service # terminate program mov $sys_EXIT, %eax # system-call ID-number mov $0, %ebx # use zero as exit-code int $0x80 # invoke kernel service #------------------------------------------------------------------ .global _start # make entry-point visible #------------------------------------------------------------------ .end # nothing else to assemble