x86 Assembly on Mac OS X
Quicksilver31337 asks: "I am currently taking an Assembly course which requires that I be able to compile ASM for the intel x86; however, I am stubbornly a Mac user. Having no desire to switch from my Powerbook, what can I do to work with, compile, and run x86 ASM short of running VirtualPC?" While Mac OS X does use gcc and its associated tool-chain, an old Slashdot discussion seems to imply that cross-compiling is better under OpenDarwin than Mac OS X. Has anyone tried cross-compiling under both operating systems? If so, what suggestions on setting up a working tool-chain do you have?
Get NASM (Netwide Assembler) and DOSBox or Bochs (x86 emulators).
Your two choices are emulation (like VirtualPC) or new hardware.
My advice is go to a computer show, buy an old, fully-functional 386, 486, or Pentium based machine, and install either DOS or Linux or *BSD. You could probably get one for less than $50.
Lex orandi, lex credendi.
Why not use bochs? It's open, free, and if you're using assembly, you won't need to worry about speed issues.
#3: get a shell account on an x86 machine.
I would think that if you want to take an assembly class for a particular architecture, you'd want to know how that architecture REALLY responds: no kind of emulation is going to guarantee you that knowledge. You're being too stubborn; get (or borrow) a cheap beige box to do the assembly work on and just rdc or vnc into it. Then turn around and sell it when you no longer need to do assembly.
Wine HQ
and
NASM
I've had good luck usings bochs http://bochs.sourceforge.net/ for x86 on my powerbook. It's a little work getting the bochsrc set up just right, and installing an os on the disk image if you need one to support the code... (I've been dorking with os-less stuff...)
-Erik
If you have no desire to change from your Powerbook, why program at all? Would it not be best to compile ASM for x86 other than on, an x86 platform? Maybe I don't understand?
"I cannot think of any need in childhood as strong as the need for a father's protection." -- Sigmund Freud
Your only real option is to get access to real x86 hardware, either by purchasing a junker Pentium box for $50 on eBay, or by getting a shell on a non-Mac-loving friend's machine. You will probably do better off having your own box, however, as it will give you direct access to video and other such things.
You're planning on testing your assembly programs in Virtual PC right? Why not simply run the assembler and debugger in Virtual PC? Am I missing something?
Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
You obviously do not understand the problem. Assembly is NOT cross platform. No way, no how.
The fact that you asked this question suggests you are in the wrong area of study. I know it sounds like flamebait, but face it, anyone who asks this question has no business programming at all. You clearly have no clue what is really going on. Find something to do with your life that you do have a clue in.
Why compile it for a PC on a Mac? Stick with the mac!
I hate using anything other than my PowerBook these days, but I honestly can't see any good arguments for not just sucking it up and working with the most appropriate hardware for the task.
Obliteracy: Words with explosions
...taking an Assembly course...
Talk to your professor, that's what they're there for! I'm sure they've had other students who either didn't have computers or had Macs like yourself.
I am stubbornly a Mac user
OK
I am currently taking an Assembly course which requires that I be able to compile ASM for the intel x86
Shouldn't you currently be taking a ballet course that requires you to go en pointe?
You've got the option of either Emulation or new hardware, as quoted by everyone on here. But there is probably a better way than both. Ask your teacher at your school if there's a box available in the IT department that's the correct archetecture. Like, for example, I am also a vehement mac user, and I had a project that required me to use assembly (mainly SSE-related things). Since I didn't know assembly for the PPC yet, I asked my professor and he said to get an account with the school's super computer. So I did, I wrote the software, and got an A on the project. Simple as that. VNC is your friend.
"Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is." G.W.Bush
Does the class specify any particular assembly language and macro set? Will nasm work or do you have to assemble masm code?
Will the class be OS specific. will you be using protected mode at all?
Which x86 features will you be using - 8086/8088, 286, 386, beyond?
How important will low level interaction with the system be? Will you be using the support chips, data bus, and timing memory operations at all?
I'd really say your best bet if you will be doing any work in how actual systems operate then you should accept a little x86 dirtiness in your life and buy an old clunker for $50 or so.
Get the experimental OS X installer for QEMU. This will emulate an x86 processor plenty fast enough to do some assembly coding. Then you can install some GNU/Linux distribution with the tools you need. Or if you want to keep this lightweight, install FreeDOS and the NASM assembler.
Wenn ist das Nunstruck git und Slotermeyer? Ja!... Beiherhund das Oder die Flipperwaldt gersput!
So get off your soapbox of not wanting to give up your MAC or get out of the class. This doesn't mean you have to give up an MAC. Use it 'til you're blue (or is it Aqua) in the face for everything else but for this class use an x86. Why make more problems for yourself?
If you want to save yourself a lot of effort, do it on x86 hardware. You don't have to own it, just connect to somebody elses box. BUT if you absolutely have to do it the hard way, then there are two things you need to address. 1. Assembling the code. Assemblers are much more lightweight than compilers. And there are probably hundreds of x86 assemblers of various qualities out there. You probably don't have to mess around with building a GCC toolchain. You can probably find the source code for an x86 assembler and compile it on OS X. If not, then just run the assembler under your x86 emulator. 2. Running the code. I think by defintion, any hardware or software that executes x86 machine code is technically an x86 CPU or emulator. Bochs, or Wine ought to work well and are both free. But there really is no getting around having either x86 hardware or emulation capabilities.
-73, de n1ywb
www.n1ywb.com
Now, what I would suggest you do is get a copy of QEMU. I assume you are familiar enough with Terminal and the shell prompt to get it working since you're stepping into the world of assembly, but if all else fails you can get QemuX or some other QEMU GUI off of VersionTracker.
Depending on what mode you're writing your assembly in, you'll need to install some sort of OS into QEMU. Some candidates are FreeDOS, MS-DOS, or even Linux. Use whatever your class is using. Emulators are very handy for writing assembly because you can debug the program at the "CPU" level, so when your program pukes you can get a better glimpse at what is going on. This is why many developers design inside of VMWare.
I hope this helps!
Beware, Nugget is watching... See?
I took a required X86 ASM course, and I used Mac OS X to do it. I wouldn't, however, run XP while coding ASM... it's just too slow on my G4 powerbook. Try DOS instead. Running MASM (ASM linker/compiler) under DOS is pretty speedy. Since Microsoft bought Virtual PC, it's hard to find a copy of VPC that doesn't include Windows (for way more money than Connectix sold it for), but you can get it at academicsuperstore.com for $119 without an OS. It worked well for me, and I didn't have any inconsistencies between running it on my Mac and running it on native x86 hardware.
She loves me: 09F911029D74E35BD84156C5635688C0 She loves me not: 09F911029D74E35BD84156C5635688BF
I tried to use virtual PC with a86 and d86 (an 8086 assembler and debbuger) and the program crashed. I'm not sure the emulation runs quite that deep. Whatever the reason, it didn't work.
First, install QEmu. (I prefer to install it through DarwinPorts)
Then download a x86 Linux Live CD ISO, for example Knoppix.
Then:
$ qemu -cdrom knoppix.iso -boot d
Simple as that. Networking will work out of the box.
You can also install Debian on a virtual harddrive using:
$ dd if=/dev/zero of=sarge.hdimage bs=1000000 count=2000
$ qemu -hda sarge.hdimage -cdrom debian-netinst.iso -boot d
When installed, start QEmu with:
$ qemu -hda sarge.hdimage
Even better, after installation, copy the kernel and the initrd to your Mac (using sftp) and start qemu with:
$ qemu -hda sarge.hdimage -kernel kernel-file -initrd initrd-file -append "root=/dev/hda1 console=ttyS0,38600" -nographics
Then you will get the console on a virtual serial port (which is your current terminal window) and it doesn't have to emulate any graphics at all.
My other account has a 3-digit UID.
Back in my day, we had to learn MIPS assembly, and this was long after the era of MIPS processors being available on campus. Instead, we had to use the SPIM emulator to test our MAL code. It seemed to fit the professors needs, but I think the professor may have had a hand in writing it. (wisc.edu)
I'd say ask the professor what he/she thinks of using Bochs first. If they aren't totally against it, it should be fine. Freshman year, it felt like I was the only one in my CS course with linux at home, but my professor had no problem with it as long as my stuff worked on the sanctioned C compiler (in a *nix) we used in the labs. As long as it tested good on the machine it was tested on, it was fine. Heck, what if the professor is just going to use Bochs anyway?
Lycestra
...and performs a bit better than Bochs. Install a smallish distro like Crux. QEMU also is supposed to support Windows 95/98/ME/2K but Bochs will probably prove to be more compatible. Don't expect speed demon performance and you'll be OK.
AC
Sweet Baby Jesus and the Orphans, if you don't want to use anything except a Mac, then go on a PowerPC assembler course!
Dear Auntie Slashdot,
I'm going on a course to learn how to stab people. But I don't like knives, nasty sharp things, I much prefer my sock full of spagetti. Can you suggest a way I can stab people with a sock full of pasta?
Also, I don't want to ride a bicycle, any way I can learn how to ride one while on a train?
etc. etc.
~~~~~ BigLig2? You mean there's another one of me?
coz assembly on a shell account, for a student, is going to be stable as hell.
.. but there are definitely times when i need to run PC software. i have a WinXP image i regularly boot into to do compiles, and it works fine .. it may not be the fastest system around, but it sure gets the job done, and leaves me to my powerbook in peace .. in fact, i've never been such a happy windows user as i am, now able to freeze a machine and restore it to its 'last known working state' .. running winXP in a VM seems to be the only way to maintain sanity, anyway ...
not the best suggestion so far, i think. you know how easy it is to crash x86 with assembly?
what i do: use VirtualPC. like the article submitter, i am 100% devoted to my powerbook
; -- the corruption of government starts with its secrets. a truly free people keep no secrets. --
You might consider bochs (http://bochs.sourceforge.net) if you can figure out how to set it up. It's slow as crap, but how complicated are your apps going to be in an intro asm course. Install a basic Linux or freebsd distro on it and go to town.
I've personally done ARM cross compiling with GCC on an x86, and I found the experience to be torture. cross compiling sucks when you have to set up the compiler and environment yourself. Maybe it works the first time, but as soon as you have a problem, it's just hell finding and fixing it.
qemu now compiles and runs under OS X and you can install MS operating systems (DOS, Windows) inside it. This is certainly cheaper than virtual PC, and the speed is not too bad. For small programs that you are writing, emulated slowdown should not pose a significant problem.
This is almost certainly an intro course. He's not writing device drivers, he's going to be writing an implementation of dijkstra's algorithm or binsort or matrix arithmetic or something. I doubt he's going to have to analyze pipeline and branch prediction behavior either. So just throw it into an emulator, it'll be fine.
Your prof sincerely will NOT CARE that you used virtualPC or whatever, as long as you did the assignment. He WILL care if you're some whiny fanboy who can't stop moaning about how kludgy and crocky the x86 architecture is and how you sing love songs to your powerpc mac every night and how you had to condescend to use an emulator only IF this dinosaur of a professor who stoops so low to use this architecture might deign to look up to your lofty height and permit you to use an emulator blah blah. Just use the damn emulator and hand in the assignment. Chances are he won't notice, and if he does, then go buy a cheap old PC and get on with life.
I am no longer wasting my time with slashdot
While Mac OS X does use gcc and its associated tool-chain, an old Slashdot discussion seems to imply that cross-compiling is better under OpenDarwin than Mac OS X.
And what does that have to do with the price of tea in china?
We're talking about Assembly here...you wouldn't use gcc.. you'd use GAS (which is awful).
NASM will compile on OSX, but it uses AT&T syntax, rather than intel syntax.
Odds are good that you're going to be learning Intel syntax.
AT&T syntax: movl %eax, %ebx
Intel syntax: mov ebx, eax
... but my university has a collection of Linux machines that you can SSH into for various uses, including development tasks. Any "decent" university (no offense intended), I think, would have a similar configuration.
Then you almost certainly have access to an x86 server of some sort. Put in X11 for OSX, and just SSH in to whatever you've got access to. If you don't know, ask the instructor. The benefit here is that you have the tools to build and run on the same machine the instructor. I'm not sure if Emacs has a x86 ASM highlight mode, though the feature is hardly nessecary.
I Browse at +4 Flamebait
Open Source Sysadmin
Code the assignment in PPC assembly and hand that in. And insist PPC is a superior architecture to code for...
ELOI, ELOI, LAMA SABACHTHANI!?
Cross compiling won't help unless you can run it too, and you're not going to be able to run it without hardware or emulation.
I'd be shocked if your uni didn't have an x86 machine that you can SSH to. Easiest to just use that.
I rarely criticize things I don't care about.
I am stubbornly a Mac user. Having no desire to switch from my Powerbook...
I think you will fail as a programmer if that is your path. Your dogma is not based in pragmatism. Please reconsider any decision that is... well, childish.There's another emulator which can just run programs instead of a whole operating system called qemu. It's free software based on GCC. Just use Google to find it.
You'll always be a user, and never an engineer, if you marry a platform.
I know quite a few engineers who used to work at Apple, and decided OS X wasn't a "Macintosh." Apple had other ideas. They're now writing Windows code.
I think the native platform for x86 is the best choice for x86 development. If you can't figure out how to use it, you have no reason to be studying software.
What do you mean, "how that architecture REALLY" responds?" The whole point of an "architecture" is that there can be more than one implementation of said architecture. AMD and Intel provide hardware implementations of the x86; VirtualPC, bochs, et al. provide software implementations of it. Differences amongst those different implementations come down to either unspecified parts of the architecture, or bugs, be those bugs in hardware or software.
Bochs is every bit as real an implementation of the x86 as a Pentium 4. In the outrageously unlikely event that bochs doesn't run this guy's assembly code correctly, he should report a bug, just as he would do in the even more outrageously unlikely event that an Intel processor runs his code wrong.
Somebody had already mentioned SSH into a remote PC, but since the original post mentioned MASM (Microsoft ASM), what about the free version of Remote Desktop from Microsoft to log into a Windows Server that has MASM loaded on it? This takes care of testing on the actual hardware, and the user still doesn't have to touch a non-Apple keyboard.
As has been said, get a junky PC. IA32 PC does not mean Windows; get an old one and run Unix on it, or some flavor of DOS. If you're using Linux and it's a recent computer at all, use VNC and some sort of filesharing to make it feel like part of your Mac.
Using an emulator (bochs, VirtualPC, etc) is a fine plan, but you wouldn't want to have to use it for editing and compilation: too slow and clunky. Get the gnu toolchain up in a cross-development way, either through debian GNU-darwin or (my preference) the NetBSD pkgsrc tree.
-- Andrew
As a Mac user who has contributed to a popular assembly language text book, I can say with some authority that VirtualPC will get you by pretty well. Some of the advanced terminal functions will fail if you're not it DOS, but they'll work better under VPC w/ DOS than a real PC and XP.
I would suggest you visit iDevGames (http://www.idevgames.com) and ask in their forum. Over 500 Mac developers (and PC) game developers hang out there. Even though the site is geared towards game development, many members will be able to help you.
Deer Mason's Guild,
I need to build a brick fireplace but I am a fervent hammer user. I realize that a hammer might not be the right tool to lay down the mortar, but I believe very strongly in the hammer and believe that ultimately, the trowel is an inferior tool designed only for trogladytes and people who actually know the definition of "trogladytes." What is the best way to use my hammer to accomplish my goal?
Signed,
Go Hammer, Go Hammer Go
That would be an inexpensive start..
---- Booth was a patriot ----
I do C/C++ cross compilation from Mac OS X to Win32 all the time, but haven't done it with assembly code.
I use both gcc and CodeWarrior, and generally haven't had any problems with either.
I have OS X binaries for Win32 gcc 3.3.2 compilation (using mingw32) available here as a torrent
Awesome piece of code to learn and experiment with:
Emu8086 Home
If you need help with binary, check out my Binary Tutorial. It also features a hex tutorial and a binary finger counting tutorial.
John
Admin
The Lyzrd's Stomp
(Photoshop tutorials and more)
...was in MIPS. I don't own a MIPS box, nor would it be easy for me to find one. It wasn't expected that we had one. We were expected to use spim/xspim/PCSpim. I ran xspim on my Mac and it was fine. The programs probably ran like a snail crawling through molasses in January in comparison to a real box, but I never noticed -- none of my programs took long enough to execute anyway.
I mod down pyramid schemes in sigs.
This website seems to have a list of places that will give you a free shell account, which you can use to compile your code using gcc or the like.
Do you have access to a computer lab on campus? Could you do the work there?
It's good to use your head, but not as a battering ram.
what can I do to work with, compile, and run x86 ASM short of running VirtualPC?" While Mac OS X does use gcc and its associated tool-chain, an old Slashdot discussion seems to imply that cross-compiling is better under OpenDarwin than Mac OS X.
There is no compiling of ASM, much less cross-compiling. ASM is assembled into machine code.
ASM is so close to the hardware, that it does not lend itself to be "cross" anything. If you did make a program to take x86 ASM and make it PPC machine code, you would have one very slow buggy program.
An interesting piece of information for all the raving zealots on both sides of the argument to note: the first AMD64 (Opteron/Athlon 64) port of Linux was done on a software simulator, before any hardware was available.
Software isn't a bad choice, especially nowadays with good free emulators such as bochs. The kind of things you'll be doing for a class assignment will not require cutting-edge performance, merely the ability to execute the code correctly. All the extra debugging facilities that come with emulators can be very useful. Especially if you're very used to one instruction set and then have to code for a completely different one, it's all very well reading the manuals, but when you actually try it, you'll be surprised. The difference between x86 and RISC (e.g. PowerPC, MIPS, ARM, SPARC) is enormous.
Stick Men
...using Universal SoftPC I was able to assemble and run all my x86 ASM programs for a freshman class on my Performa running MacOS 7.
I know quite a few engineers who used to work at Apple, and decided OS X wasn't a "Macintosh." Apple had other ideas. They're now writing Windows code.
No you don't, liar.
Yeah, this has little to do with the question, but I'm asking anyway.
x86 is a popular choice for the simple reason that it's the only architecture that runs most Windows apps. A modern x86 CPU is very fast. The assembly language is rather difficult, there's very little need for that sort of performance on any x86, and no need to use x86 for any embedded applications.
It just seems to make more sense to use a simpler processor to teach the concepts of assembler, and most people who already know assembler for a couple of machines aren't going to need a course for a new architecture.
to me the obvious answer is to ssh into a CS department computer. i have to assume there are some; my CS dept had several dozen and you could ssh into any of them, or go and sit in front of them yourself.
what am i missing? the answer is so obvious.
Qemu has been ported to Mac OS X, and it is possiable with crosstool (http://www.kegel.com/crosstool/) to build a cross-compiler fairly easily. Failing cross-tool, it's just a task of building everything in the correct order and applying any recent patchs from the GCC bugzilla. I don't know if crosstool has support for building a i{3/4/5/6} compiler, but you can easily add new targets by modifying a few of the dat files.
This signature was left intentionally blank.
Slashdot ought to get some editors who are not clueless. This is a total non-story. Anyone who knows anything about the topic would just say, "use nasm, kid," and that would be the end of it.
But Cliff's interjection is even stupider than the mere fact that this article even exists (which is in itself ridiculous). Cliff, do you write code? Do you know the difference between a compiler and an assembler? No? Then don't try and contribute.
I went back to college about ten years ago and got myself a somewhat belated CS degree. I used a Mac (Quadra 800) at the time, and three of my classes (in the first two semesters) required PC software. (After a while they all ended up requiring a Sun workstation, a MIPS workstation, or the IBM System 3/70 (yuch!).
I used SoftPC (remember that?) and it all went just fine. Using emulation software to complete these sorts of courses was often better than doing it natively: I could run the DOS applications in one window and still be able to check my email and run a 'talk' session in the background at the same time.
I'm sure Virtual PC would work fine these days, even if it is a Microsoft product now.
-fred
Sign #11 of Slashdot overdose: You see the phrase 'moderate Republican' and you wonder if that would be a +1 or a -1.