linux - x86 GNU Assembler Strange Change Seg Fault -
the following x86 assembly code assembles fine, , used run flawlessly on school's linux server, when applying same code linux virtual machine (ubuntu 14.04, of sudden causes segmentation fault.
did stack conventions change, gnu assembler problem? memo did miss? running on 64-bit machine, , warm-up building backbone of os, need able use 16-bit real, 32-bit protected, , 64-bit mode in same program. suppose need little details making modes valid in same program. know use .code16/32/64 when changing modes, guess i'm missing (and can't seem find in os tutorial, how on 64-bit architecture.
.code32 .text .global _start _start: pushl $str1 pushl $len1 call print addl $8, %esp <-cleans stack pointer exit: movl $1, %eax movl $0, %ebx int $0x80 print: pushl %ebp movl %esp, %ebp movl $4, %eax movl $1, %ebx movl 12(%ebp), %ecx <- seg fault occurs according gdb movl 8(%ebp), %edx int $0x80 popl %ebp ret .data str1 : .ascii "string1\n" len1 = . - str1
i'm guessing have 64-bit machine, while program 32-bit.
i have 64-bit machine, if compile command, fails, same line you:
$ gcc -nostdlib test.s
however, if compile 32-bit executable:
$ gcc -nostdlib -m32 test.s
and fine.
note may need packages able compile 32-bit program in 64-bit machine (g++-multilib
or whatever call these days).
Comments
Post a Comment