0

I'm trying to convert a NASM code to GAS. I can't make the lea instruction work.

Here's my original code and this completely works:

section .bss
   arr resb 10

section .text
   global _start:

_start:
   push arr
   call getInput
   ...

getInput:
   mov esi, 0
   mov ebp, [esp+4]

   loop:
   ...      
   mov eax, 3
   mov ebx, 0
   lea ecx, [ebp+esi]
   mov edx, 2
   int 80h
   ...

And here's the GAS counterpart I'm trying to write:

.data
   arr:     .space 10

.text
  .globl _start

_start:
   push arr
   call getInput
...

getInput:
   movl $0, %esi
   movl 4(%esp,1), %ebp

  loop:
  ...
  movl $3, %eax
  movl $0, %ebx
  leal (%ebp,%esi), %ecx
  movl $2, %edx
  int $0x80

I've been searching for hours on how to properly do it but I can't find a tutorial on this matter. It produces a segmentation fault when I run it. Please help me.

P.S. I use these commands to compile and link (thanks to someone here who answered my previous question):

as --32 -o sample.o sample.s
ld -m elf_i386 -o sample sample.o
bubbly
  • 1
  • 1
    The `lea` is fine, the problem is the `push arr` which should be `push $arr` as already pointed out by Frank in [your other question](http://stackoverflow.com/questions/26956080/conversion-of-nasm-to-gas). – Jester Nov 16 '14 at 15:50
  • @Jester Oh, my mistake. Thank you very much. :) – bubbly Nov 16 '14 at 18:11

0 Answers0