PDA

View Full Version : assembly in mac




uaecasher
Mar 2, 2009, 02:42 PM
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



lee1210
Mar 2, 2009, 02:47 PM
http://forums.macrumors.com/showthread.php?t=455794

This thread might be a good place to start.

-Lee

LtRammstein
Mar 2, 2009, 02:47 PM
As far as I know the assembly used by OS X and Windows, on the Intel chipset, is i386 (x86).

Flynnstone
Mar 2, 2009, 09:16 PM
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.

LtRammstein
Mar 3, 2009, 09:14 PM
Microprocessors Ftw!!!

F- Yeah Seaking!

micsaund
Mar 3, 2009, 10:23 PM
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.

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 (http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002) software is free and integrated nicely with a simulator, so you could get programming without even owning a chip/programmer.

Mike

Cromulent
Mar 3, 2009, 10:49 PM
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

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.

Muncher
Mar 4, 2009, 09:18 AM
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.

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 (http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002) software is free and integrated nicely with a simulator, so you could get programming without even owning a chip/programmer.

Mike

The first assembly language I learned was for the PICs too. It's really simple, but it can be kinda frustrating. Look here (piclist.com) if you feel like trying that out.

ChrisA
Mar 4, 2009, 09:44 AM
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.


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.

Cromulent
Mar 4, 2009, 10:01 AM
The first assembly language I learned was for the PICs too. It's really simple, but it can be kinda frustrating. Look here (http://piclist.com) if you feel like trying that out.

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.

uaecasher
Mar 4, 2009, 10:07 AM
well guys I don't want to learn assembly for making programs, I'm interested in reverse engineering

Cromulent
Mar 4, 2009, 10:20 AM
well guys I don't want to learn assembly for making programs, I'm interested in reverse engineering

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.

gnasher729
Mar 4, 2009, 01:19 PM
well guys I don't want to learn assembly for making programs, I'm interested in reverse engineering

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.

uaecasher
Mar 5, 2009, 03:44 AM
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.

:eek: that's sure too much :D

LtRammstein
Mar 5, 2009, 01:36 PM
Find a language, like Motorola Freescale's assembly, and just learn it. It's the only way you can understand how assembly works.

hiddenpremise
Mar 5, 2009, 10:41 PM
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.

gnasher729
Mar 6, 2009, 06:44 AM
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.

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.

AUFan
Mar 10, 2009, 01:32 PM
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.

Muncher
Mar 10, 2009, 03:42 PM
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.

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.

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.

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 (http://www.int80h.org/).

I did find one interesting project as I was googling around to find stuff about intel ASM: MenuetOS (http://www.menuetos.net/). 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.