Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Nasm Asembly help?

Name: Anonymous 2010-04-04 21:39

I'm having some problems figuring out how to program in x86_64 assembly.  None of the classes I've taken on assembly have ever trained me on modern assembly programming, and I figured it would make me reach satori, so I would like to learn it.  I found this code online, and I was trying to get it to work on my ubuntu system.

   1.
      global _start
   2.
      
   3.
      section .data
   4.
      hello db "Hello, World!", 10
   5.
      length equ $-hello
   6.
      
   7.
      section .text
   8.
      
   9.
      _start:
  10.
      mov eax, 4 ; write to file
  11.
      mov ebx, 1 ; STDOUT handle
  12.
      mov ecx, hello ; our message
  13.
      mov edx, length ; size of message
  14.
      int 80h ; execute the syscall
  15.
      
  16.
      xor ebx, ebx ; send 0 as 'exit code'
  17.
      mov eax, 1 ; terminate process
  18.
      int 80h ; execute the syscall

When I was linking the object code it gave me an error about how it isn't compatible with my architecture.  What is so different about i386 and i386_64 programming?

Name: Anonymous 2010-04-04 21:46

Or does it have entirely to do with the linker?  When I inject i386_64 it gives me a weird bug and does not go any further.  Something about nonreferenced memory locations.

Name: Anonymous 2010-04-04 22:09

Is my question that stupid?

Name: Anonymous 2010-04-04 22:21

>>3
/prog/ consists of like, 3 people at a time. Be patient.

Name: Anonymous 2010-04-04 22:31

>>4
For what? Who would find this interesting enough to answer?

Name: Anonymous 2010-04-04 22:33

OP why don't you just decompile (objdump -d) a C program that does the same and look at the output?

Also, you should look at the x86_64 ABI (which has important differences from the traditional x86 one). Take that into account.

Name: Anonymous 2010-04-04 23:10

Note to >>1:
The proper way to format code here is not unlines $ zipWith (++) (map ((++ ".\n    ") . show) [1..]) (lines postBody).

Name: Anonymous 2010-04-04 23:59

>>4
/prog/ consists of like, 3 people. Be patient.

FTFY

Name: Anonymous 2010-04-05 3:06

>>8
and 33% of them are on /sci/ now

Name: Anonymous 2010-04-05 4:00

When I was linking the object code it gave me an error about how it isn't compatible with my architecture.
Then you're assembler or linker is set to the wrong architecture, or your trying to mix in libraries from a different arch.  Don't do that.

What is so different about i386 and i386_64 programming?
See >>6.

Name: Anonymous 2010-04-05 13:37

…………………...„„-~^^~„-„„_
………………„-^*'' : : „'' : : : : *-„
…………..„-* : : :„„--/ : : : : : : : '\
…………./ : : „-* . .| : : : : : : : : '|
……….../ : „-* . . . | : : : : : : : : |
………...\„-* . . . . .| : : : : : : : :'|
……….../ . . . . . . '| : : : : : : : :|
……..../ . . . . . . . .'\ : : : : : : : |
……../ . . . . . . . . . .\ : : : : : : :|
……./ . . . . . . . . . . . '\ : : : : : /
….../ . . . . . . . . . . . . . *-„„„„-*'
….'/ . . . . . . . . . . . . . . '|
…/ . . . . . . . ./ . . . . . . .|
../ . . . . . . . .'/ . . . . . . .'|
./ . . . . . . . . / . . . . . . .'|
'/ . . . . . . . . . . . . . . . .'|
'| . . . . . \ . . . . . . . . . .|
'| . . . . . . \„_^- „ . . . . .'|
'| . . . . . . . . .'\ .\ ./ '/ . |
| .\ . . . . . . . . . \ .'' / . '|
| . . . . . . . . . . / .'/ . . .|
| . . . . . . .| . . / ./ ./ . .|

Name: Anonymous 2010-04-05 14:19

different assemblers have different syntax, something for GAS or MASM wont run on NASM

Name: Anonymous 2010-04-05 14:28

>>12
What a GAS!

Name: Anonymous 2010-04-06 6:28

Name: Anonymous 2010-07-22 21:09

OP, what you have is x86 assembly. If you're on an x86, do this:
$ nasm -f elf -o dicks.o dicks.s
$ ld -o dicks dicks.o


If you're on x86_64, do this:
change your assignments to eax to 4 and 60, resp.
$ sed -i 's/e\(..\)/r\1/g; s/int 80h/syscall/' dicks.s
$ nasm -f elf64 -o dicks.o dicks.s
$ ld -o dicks dicks.o

Name: Anonymous 2010-12-27 16:45

Don't change these.
Name: Email:
Entire Thread Thread List