• Uncategorized

About linux : Assembling-32-bit-binaries-on-a-64-bit-system-GNU-toolchain

Question Detail

I wrote assembly code that successfully compiles:

as power.s -o power.o

However, it fails when I try to link the object file:

ld power.o -o power

In order to run on the 64 bit OS (Ubuntu 14.04), I added .code32 at the beginning of the power.s file, however I still get the error:

Segmentation fault (core dumped)


.section .data
.section .text
.global _start
pushl $3
pushl $2 
call power 
addl $8, %esp
pushl %eax 

pushl $2
pushl $5
call power
addl $8, %esp

popl %ebx
addl %eax, %ebx

movl $1, %eax
int $0x80

.type power, @function
pushl %ebp  
movl %esp, %ebp 
subl $4, %esp 
movl 8(%ebp), %ebx 
movl 12(%ebp), %ecx 
movl %ebx, -4(%ebp) 

cmpl $1, %ecx 
je end_power
movl -4(%ebp), %eax
imull %ebx, %eax
movl %eax, -4(%ebp)

decl %ecx
jmp power_loop_start

movl -4(%ebp), %eax 
movl %ebp, %esp
popl %ebp

Question Answer

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.