Running 32-bit Assembly Source files on a 64-bit Ubuntu Linux installation

33 Views Asked by At

I am trying to run this code that I recieved for one of my classes:

#32bit version

#PURPOSE:  Simple program that exits and returns a
#          status code (42) back to the Linux kernel
#
#INPUT:    none
#
#OUTPUT:   returns a status code.  This can be viewed
#          by typing
#
#          echo $?
#

# %eax holds the system call number
# %ebx holds the return status


.section .text
.globl _start
_start:
    movl $1, %eax #1 -> exit
    movl $42, %ebx #return 42
    int $0x80 #run kernel

I then assemble, link, and try to run it using:

as exit.s -o exit.o
ld exit.o -o exit
./exit

which results in a Seg fault. What am I doing wrong? I'm not sure whether it's installation or code related as I am quite new to both assembly and linux. I am getting all the code from the textbook that we are to follow.

I have tried following suggestions online and installed various packages through sudo such as gcc-multilib, g++-multilib, libc:i386, libncurses5:i386 libstdc++6:i386. I also did add the i386 architecture. I have also tried assembling with -m32 but that caused an error. I have found a 64 bit version of the program and it does work but this course is going to be taught in 32 so I would like it to work as well.

I have looked online for a while and haven't found anything that has helped me, as in a lot of questions like the one I have, people are using gcc to compile .c files which (to the best of my knowledge) is not applicable in my situation.

Thank you for your time.

0

There are 0 best solutions below