2 Replies - 475 Views - Last Post: 07 November 2019 - 03:33 AM

#1 SuchtyTV   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-November 19

Getting into x86 Assembly - nasm does not compile

Posted 06 November 2019 - 12:03 PM

Good evening,

I am currently taking a curse in computer architecture and try to implement my first assembly programm (which is not really efficent yet, but who cares)...

I am compiling with nasm.
start:
        mov %eax, 66567;
        mov %ebx, 7435;
.B:
        CMP %eax, %ebx;
        JNE .A;
        JMP .END;
.A:
        JLE .C;
.SUB:
        SUB %eax, %ebx; 
        JMP .B;
.C:
        XCHG %eax, %ebx;
        JMP .SUB;
.END:
        PUSH %rax;
        PUSH $message;
        CALL printf;
        RET;
message:
        .ascii "%d\n"
~                              



NASM complains:

gauss.s:2: error: expression syntax error
gauss.s:3: error: expression syntax error
gauss.s:5: error: expression syntax error
gauss.s:11: error: expression syntax error
gauss.s:14: error: expression syntax error
gauss.s:17: error: expression syntax error
gauss.s:22: error: parser: instruction expected

Could you help? How to assemble this file with gcc to a executable?

Thank you!
Have an awesome day!

Is This A Good Question/Topic? 0
  • +

Replies To: Getting into x86 Assembly - nasm does not compile

#2 SuchtyTV   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-November 19

Re: Getting into x86 Assembly - nasm does not compile

Posted 06 November 2019 - 12:09 PM

Furthermore I am wondering if RET clears the stack properly, and how to deal with the stack pointer, as well as the base pointer...

(Did not find an edit button...)
Was This Post Helpful? 0
  • +
  • -

#3 Ornstein   User is offline

  • New D.I.C Head

Reputation: 22
  • View blog
  • Posts: 43
  • Joined: 13-May 15

Re: Getting into x86 Assembly - nasm does not compile

Posted 07 November 2019 - 03:33 AM

It looks like you're using AT&T syntax, but NASM (if I'm not wrong) only supports Intel syntax. You either need to use Intel syntax or find an AT&T assembler (gas, maybe?)

Your second question is a bit vague. What do you mean by "clearing the stack properly" and "dealing with the stack pointer"?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1