Asm?

Member
Posts: 312
Joined: 2006.10
Post: #1
Is it possible to code for the Mac with some type or ASM? I know there are various versions of ASM specific for the computer's/machine's architecture. For example, MIPS...
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #2
I would highly recommend you do not use assembly. For one thing, Macs now use 2 different architectures, each with completely different ISAs and assembly. Also, with compilers, it's very much unnecessary.

If you really want to use assembly for some reason, you're going to have to either use PPC assembly for PPC-based Macs, or X86 assembly for Intel Macs.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
Yes.

I'm not quite sure why you'd want to, of course...

Probably the easiest is to write the ASM within a C file --

Code:
int main(int argc, const char **argv[]) {
    asm {
        // your asm code here
    }
}

Then compile on the command-line with

Code:
gcc main.c -o myAssemblyProgram

and run with

Code:
./myAssemblyProgram

Obviously, you'll need to use PowerPC assembly if you have a PowerPC Mac, and Intel assembly if you have an Intel Mac.

You could also get "spim" (an X11-based MIPS simulator) from DarwinPorts or Fink, and use that.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
I want to get into ASM myself, but it will be a long time before I can do anything with it. Anyway, if you can write somthing in C but not in assembly, you can use the gcc -S flag to see assembly code generated from a C source file, of course computer generated assembly wont be the most verbose but I guess it could be useful in some circumstances.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #5
Compiler-generated assembly, at least on the PPC, will likely be very different from the assembly you'd write. There's a lot of "fake" commands that are expanded into 2 commands (or sometimes more) for very simple things, such as moving a 32 bit immediate into a register along with some branch conditions. (since there may not be room in the fixed-length instructions to do it all in one instruction; this isn't as necessary with X86, with the variable instruction lengths allowing for more flexibility in the ISA) As a result, the compiler will generally have the complicated versions already written out rather than the faked commands. I believe the commands for moving the stack pointer are another example.
Quote this message in a reply
Apprentice
Posts: 17
Joined: 2006.10
Post: #6
As well, a lot of things you might write assembly for, like taking advantage of vector instructions, is wrapped up in Accelerate.framework. DSP functions, matrix multiplication, etc.

Of course, if you want to learn assembly for the sake of simply learning it, then I'd suggest starting with an 8-bit processor, like the 6809 or something, since there are plenty of tools and many emulators. The instruction set is smaller, and thus easier to get a handle on. Although RISC instruction sets, like MIPS and PPC, are pretty straightforward.
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #7
Yeah, I just want to learn it for the sake of learning it. Also I want to see how the cpmputer really executes code, and how the cpmuter it self works.

What other systems does MIPs run on?
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #8
MIPS runs on just that, MIPS. However, as OSC said, you can install an emulator called SPIM. (or MIPS backwards) Assuming it's just standard C code (and using endian aware code) it could conceivably be run on any system, as long as you have the required libraries.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
The most famous homes for MIPS chips are SGI workstations and Sony Playstations. The SPIM simulator should work everywhere that has X11 though, since it just emulates the chip.

MIPS is a good place to start, because the instruction set is simple and well-thought-out, and there are very good resources available.

(If anyone knows how to alter that link to make it use iDG's affiliate ID, please let me know and I'll fix it...)
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #10
Thanks, yeah luckly I program for the PSP, so MIPS is what I want (why I asked about it, lol)... Do you have any other (free) resources? Rasp

Anyways, the fast replies are highly appreciated Smile
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #11
LOL That's my textbook for computer architecture this quarter! Rasp (when I learned ASM, we did it in Sparc. For some reason, they decided to use MIPS for the architecture class)
Quote this message in a reply
Apprentice
Posts: 17
Joined: 2006.10
Post: #12
It's a bit of a crapshoot what asm language you get when enrolling into a university course. You can always check ahead. Sometimes you can just sit in on a class, if the professor doesn't mind, without enrolling. So if there's a university in your area that has a course that includes MIPS assembly, you can find out what the schedule is, show up the first day of classes, and ask the professor if they'd mind you sitting in on the lectures.

My own experience in university was x86 assembly *shudder*, and for our architecture class, some made up RISC that our textbook used. I started with 6809 assembly previous to getting into university, though, so I was used to thinking in that sort of space.
Quote this message in a reply
Moderator
Posts: 3,574
Joined: 2003.06
Post: #13
bronxbomber92 Wrote:Yeah, I just want to learn it for the sake of learning it. Also I want to see how the cpmputer really executes code, and how the cpmuter it self works.
Slightly off-topic: I stumbled upon a really great read a few years ago on the subject of how computers work from Microsoft Press, entitled CODE. It won't teach you how to do assembly, but it'll provide a good overview of how it's done, and it's a real easy read if you get the chance.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #14
If you need any help with your MIPS, feel free to ask me, I am current neck deep in it, and any questions you have can only further help me with what I am doing =)
Quote this message in a reply
Moderator
Posts: 452
Joined: 2008.04
Post: #15
bronxbomber92 Wrote:Yeah, I just want to learn it for the sake of learning it. Also I want to see how the cpmputer really executes code, and how the cpmuter it self works.

For just learning how assembly works, which is a valuable thing, in my opinion, I'd recommend pep/7. You can get a pep/7 emulator and try some simple programs on it. Write something to add two numbers together... and then try writing something to calculate Fibonacci numbers.

You can download the pep/7 emulator here:

http://computersystems.jbpub.com/downloadpep7.cfm

My classmates and I had a lot of success with this in our undergraduate systems course.
Quote this message in a reply
Post Reply