1

This is driving me insane... I'm sure there's something very small I'm doing wrong here, but I can't figure out what it is after trying for 30 minutes and googling. I am trying to compile a very simple C program with some inline assembly, then disassemble it, in order to get the machine code for the instructions. This is for a school programming project. Here is my most recent attempt:

int main() 
{
asm(
    "movl   $0x5bc1229f,0x0804c1e8"
    "movl   $0x08048f9c,%edx"
    "push   %edx"
    "ret"
      );
}

When I compile this, I get the errors:

/var/folders/kI/kIAe03vJFdClYy0r0mmBp++++TI/-Tmp-//cc2xKnoz.s:9:junk `movl $0x08048f9c' after expression

/var/folders/kI/kIAe03vJFdClYy0r0mmBp++++TI/-Tmp-//cc2xKnoz.s:9:bad register name `%edxpush%edxret'

Thanks for your help :)

1 Answer 1

2

Try

int main()
{
asm(
    "movl   $0x5bc1229f,0x0804c1e8\n\t"
    "movl   $0x08048f9c,%edx\n\t"
    "push   %edx\n\t"
    "ret\n\t"
      );
}
Sign up to request clarification or add additional context in comments.

2 Comments

For others reading this, the point is that anything you put in an asm statement is copied directly as-is into your assembly file. This means that you must manually add newline characters (\n) at the end of each line of assembly you write, otherwise each line will be pasted together into one long line. Tab characters (\t) at the end of each line are also traditional, but not necessary (they merely make the generated assembly from the compiler look nicer).
Wow thanks! Worked perfectly. I had read that newlines and tabs were necessary, but I wasn't putting them inside the quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.