assembly in mac

Discussion in 'Mac Programming' started by uaecasher, Mar 2, 2009.

  1. macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #1
    Hello

    I'm thinking of learning assembly and i was wondering is the assembly language in pc same as in a mac, and can anyone recommend me a book to start with. if there is a difference what is it

    I'm new in programing so be easy on me :) thank you
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
  3. macrumors 6502a

    LtRammstein

    Joined:
    Jun 20, 2006
    Location:
    Denver, CO
    #3
    As far as I know the assembly used by OS X and Windows, on the Intel chipset, is i386 (x86).
     
  4. macrumors 65816

    Flynnstone

    Joined:
    Feb 25, 2003
    Location:
    Cold beer land
    #4
    Please don't take this as being rude. I only mean to help.

    There is no such thing as "learning assembly"!

    Assembly language is specific to particular processors.
    PPC assembler doesn't work on an Intel processors. (Rosetta is crutch).
    Imagine doing a big app in assembler for the PowerPC, then Apple offers Macs with Intel processors. It could happen ;) All the assembler code is close to useless.

    The argument that assembler is faster is essentially wrong. Programmers are notorious for mistaking the code hot spots. Most often a better algorithm is a better solution. But with assembler it is likely too late, because so much has been invested.

    So don't plan on making an app in assembler! Use C or something.

    I think learning x86 is close to useless.

    Now assembler coding can be fun. Start easy with a Microchip Pic or Freescale microcontrollers. Or Arm could be useful.
     
  5. macrumors 6502a

    LtRammstein

    Joined:
    Jun 20, 2006
    Location:
    Denver, CO
  6. macrumors 6502

    micsaund

    Joined:
    May 31, 2004
    Location:
    Colorado, USA
    #6
    Not to mention that x86 is so complicated with the modern OS interactions/etc. That's what's kept me from doing anything in x86 Winbloze-land, even though I grew-up doing 6502/etc. assembly.

    I will second learning ARM or PIC. Both, especially the PIC, are small enough instruction sets that you can wrap your brain around it entirely and actually begin to take advantage of the hardware/etc. rather than just scraping the surface.

    The PIC MPLAB software is free and integrated nicely with a simulator, so you could get programming without even owning a chip/programmer.

    Mike
     
  7. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #7
    The ABI is different between Mac OS X and Windows even though they use the same CPUs. Best bet is to read the FreeBSD Assembly resources. Although be warned, documentation is sparse.
     
  8. macrumors 65816

    Muncher

    Joined:
    Apr 19, 2007
    Location:
    California
    #8
    The first assembly language I learned was for the PICs too. It's really simple, but it can be kinda frustrating. Look here if you feel like trying that out.
     
  9. macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #9

    Mostly you are right. You'd be nuts to write a big app in assembly. However it can be very useful to use asembly in some small areas of your code.

    Sometimes you have to deal with hardware Be it an obscure register in the CPU or chipset or some special hardware device you bought or even built. And then you might have an inner loop that needs to run faster or with very predictable timing. I've used assembly in small amounts for all of these reasons. Some times it is the only way to access a specific machine instruction you want. The last time I needed assembly was to drive custom hardware. It was a camera and I was writing the code to stabilize the image on the sensor and move the image data through the a/D and into a disk file.

    But mostly you don't need it much any more on PCs.

    I have used assembly a lot on micro-controllers. These are little $2 computers that have maybe 1K or RAM.
     
  10. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #10
    I'm still trying to get my AVR Butterfly working :mad:. Seems like more hassle than it is worth on the Mac and I hate booting into Windows because I lose access to my e-mail and iTunes library.

    If I thought a PIC worked well out of the box on the Mac I would snap one up in an instant.

    As for the thread in question as I stated earlier the documentation on this is abysmal. Apple provide the odd document describing the Mac OS X ABI, but at the time I was looking they only provided the 32bit Intel ABI and not the updated 64bit ABI. The only other useful information I got was from FreeBSD dev sites and a little help from one of the NASM devs to get stuff assembling correctly using the mach-o binary format.

    After about a week of frenzied Googling and reading the Intel CPU reference manuals (which by the way if you ever try and print will take about a week) I ended up with basically bugger all information. I'll probably look into again but I decided to learn assembly properly using micro controllers and then when I had a solid grasp of that I assumed it would be easier to make the jump up to 32 / 64 bit Intel ASM programming.
     
  11. thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #11
    well guys I don't want to learn assembly for making programs, I'm interested in reverse engineering
     
  12. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #12
    That's even harder. Disassembling applications does not leave you with easy to understand assembly.

    You would still need to have a pretty good grasp of assembly anyway so basically at this point in time the advice is still applicable.
     
  13. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #13
    Write some small functions in XCode, and "Show Assembly Code" from the Build menu to see what the compiler does. Better do this in a Release build, not debug. And go to www.intel.com and look for their processor manuals.
     
  14. thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #14
    :eek: that's sure too much :D
     
  15. macrumors 6502a

    LtRammstein

    Joined:
    Jun 20, 2006
    Location:
    Denver, CO
    #15
    Find a language, like Motorola Freescale's assembly, and just learn it. It's the only way you can understand how assembly works.
     
  16. macrumors regular

    hiddenpremise

    Joined:
    Jul 25, 2008
    Location:
    Somewhere between my imagination and reality
    #16
    Assembly is a low level language and dates back to the 50's. Is there any particular reason that you want to learn it? If you are new to programming and want to learn to develop applications for the mac, check out any of the threads here about Objective-C. It is fairly easy to learn the basics and get started writing your own apps. If you don't want to try a C language, maybe try a scripting language like PHP or javascript to cut your teeth.
     
  17. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #17
    For actual programming, assembly language is rather pointless except for very, very few special cases (if you write compilers or virtual machines, or you implement posix threads on a new machine, you better know assembler). On the other hand, if you like to know how things work, or if you read about new Nehalem processors and instead of believing Intel's marketing guys, you want to find out yourself, then knowing assembler is useful.
     
  18. macrumors newbie

    Joined:
    Feb 2, 2008
    #18
    I'm currently working on some assembly stuff and if you want to /need to learn IA-32 assembly, I've found this guy's book to be pretty good: http://kipirvine.com/asm/ It's one of the most straightforward programming textbooks I've read.
     
  19. macrumors 65816

    Muncher

    Joined:
    Apr 19, 2007
    Location:
    California
    #19
    I wouldn't say pointless. Difficult for sure, and not for beginners, but useful if you need a small program. Besides, it's always good to know what's going on beneath all the shiny metal :D.

    Same, I would program more for the PIC if it was easier.

    I tried looking at the Mach-o header format once; it was extremely confusing to me. I did get some useful info from here.

    I did find one interesting project as I was googling around to find stuff about intel ASM: MenuetOS. It's an operating system coded entirely in assembler; if it's still an active project, I may try to learn assembler through it sometime.
     

Share This Page