0

I'm a student and completely new to assembly programming, especially to GAS. I have a .asm program that uses selection sort to (obviously) sort an array of 10 integers and we were tasked to convert the code to GAS. I'm stuck at getting the input for the array. Here's a snippet of what I did:

section .bss
   arr resb 10

section .text
global _start:

_start:
   push arr
   call getInput
   ...

getInput:
   mov esi, 0
   mov ebp, [esp+4]    ; line number 59
   ...

The problem is, I have trouble finding out how to convert the code in line number 59. Here's what I did (loosely based on the tutorials I found):

.data
   arr:     .space 10

.text
.globl _start

_start:
push arr
call getInput
...

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

I tried running it and it produced a segmentation fault. What am I doing wrong? Am I pushing the address of the arr correctly? Is 4(%esp,1) equal to [esp+4]? Thank you in advance!

bubbly
  • 1
  • Your snippet is correct and works here. Please add the command lines to build the executable. – rkhb Nov 16 '14 at 11:05
  • @rkhb as -o sample.o sample.s and then ld -o sample sample.o – bubbly Nov 16 '14 at 11:19
  • Try `as --32 -o sample.o sample.s` and `ld -m elf_i386 -o sample sample.o`. – rkhb Nov 16 '14 at 11:56
  • 1
    I would have thought `pushl $arr`, no? – Frank Kotler Nov 16 '14 at 12:19
  • I'm actually pushing the address of the arr. Wouldn't pushing $arr mean pushing its value? I'm sorry, I'm still confused when it comes to GAS. @FrankKotler – bubbly Nov 16 '14 at 12:28
  • Dunno. I'm a Nasm bigot. My understanding is that `$arr` is the address, `arr` is the value in GASese. If it's working the way you're doing it, ignore me! – Frank Kotler Nov 16 '14 at 18:32
  • No, no. You were right. Thank you for pointing that out. I've already translated my whole NASM program. :) Big help, thanks! @FrankKotler – bubbly Nov 17 '14 at 00:08

0 Answers0