assembly - Linux AT&T command-line parameters -


this question has answer here:

i'm trying learn assembly programming on linux, googled/created simple implementation of "cat", little program not work command-line arguments (it says "colud't open file"). when uncomment "fname" line, works, file i/o fine. think stack-part broken :/ here's code:

    .code32      .section .data msg_err_open:     .asciz "colud't open file.\n" msg_err_open_len:     .long . - msg_err_open fname:     .asciz "test.txt"  .section .bss     .equ bufsize, 1024     .lcomm buf, bufsize  .section .text     .globl _start     .align 4  _start:   #   popl %ebx    # argc #   popl %ebx    # argv[0] #   popl %ebx    # argv[1] (file)      # open     movl $5, %eax       # open( #   movl 8(%esp), %ebx  #   filename, ????????????????     movl $fname, %ebx     movl $0, %ecx       #   readonly     int $0x80       # )      test %eax, %eax     # megnyitás sikerült?     js err_open     # ha negatív      # read               movl %eax, %ebx     # file descriptor eax->ebx     movl $3, %eax       # read( fd (ebx),     movl $buf, %ecx     #   buffer,     movl $bufsize, %edx #   size     int $0x80       # )      # close              movl $6, %eax       # close( fd (ebx)     int $0x80       # )      # write              movl $4, %eax       # write(     movl $1, %ebx       #   stdout,     movl $buf, %ecx     #   buffer     int $0x80       #)      # exit      movl $1, %eax       # exit(     movl $0, %ebx       #   0     int $0x80       # )  err_open:        # write (msg_err_open)           movl $4, %eax     movl $1, %ebx     movl $msg_err_open, %ecx     movl $msg_err_open_len, %edx        # length     int $0x80      # exit(1)     movl $1, %eax     movl $1, %ebx     int $0x80 

i comple/link way:

   pfile.s -o pfile.o    ld pfile.o -o pfile 

my linux distro is:

debian 3.2.41-2+deb7u2 

as version:

 2.22 (x86_64-linux-gnu) 

i think solution trivial, don't see it. want run on 32 bit mode, x64 pretty hard me now. thank time!

oh, see problem. nice have included how build program (+1 that). if check resulting executable using file command, bet says 64 bit:

$ file pfile pfile: elf 64-bit lsb executable, x86-64, version 1 (sysv), statically linked, not stripped 

to make 32 bit program should use:

$ --32 pfile.s -o pfile.o $ ld -melf_i386 pfile.o -o pfile $ file pfile pfile: elf 32-bit lsb executable, intel 80386, version 1 (sysv), statically linked, not stripped $ ./pfile pfile.s     .code32      .section .data ... 

alternatively can gcc -m32 -nostdlib pfile.s -o pfile


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -