• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NASM with Xcode 3.2 ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NASM with Xcode 3.2 ?


  • Subject: Re: NASM with Xcode 3.2 ?
  • From: Wim Lewis <email@hidden>
  • Date: Sun, 11 Oct 2009 13:48:16 -0700


On Oct 11, 2009, at 9:00 AM, Colin Howarth wrote:
Now it compiles, but the bit of code I copied from the NASM Manual (Chapter 8. Writing 32 bit code (Unix...)
crashes with asm misaligned_stack_error.

As Jean-Daniel Dupas notes, the OSX ABI is probably slightly different from the one you're writing from. In this case, I think the problem is that when you do a function call to a dynamically-linked function on OSX intel, the stack needs to be aligned to a 16-byte(?) boundary --- this is a result of the dyld stub needing to save some SIMD registers on the stack.


Any help appreciated. Not especially with the code - I just want to see something on the console :-)

Changing the 'print' function to align the stack will work. Here's an example --- I just set a breakpoint on the "call _printf" line and examined the $esp register to see how much I'd need to adjust the stack in order to align it. In this case, it's making up for the effects of the stack manipulation in _myfunc as well as in print.


print:
       sub     esp, byte 12
       push    dword [myint]   ; one of my integer variables
       push    dword mystring  ; pointer into my data segment
       call    _printf
       add     esp,byte 20      ; `byte' saves space
       ret


which produces (on my machine): $ nasm -f macho b.nasm && cc -arch i386 a.c b.o $ ./a.out This number -> 1234 <- should be 1234




_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: NASM with Xcode 3.2 ?
      • From: Colin Howarth <email@hidden>
References: 
 >NASM with Xcode 3.2 ? (From: Colin Howarth <email@hidden>)

  • Prev by Date: Re: Xcode bug re Objective-C categories
  • Next by Date: Re: NASM with Xcode 3.2 ?
  • Previous by thread: Re: NASM with Xcode 3.2 ?
  • Next by thread: Re: NASM with Xcode 3.2 ?
  • Index(es):
    • Date
    • Thread