Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / April 2007



Tip: Looking for answers? Try searching our database.

Very (very!) simple assembly language example wanted.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve555 - 29 Apr 2007 10:07 GMT
Hi,

I'm tinkering with some Genetic Algorithm stuff, and in order to see
what's happening at the most basic level, I'd like to look at some
assembler. Could anybody show me a simple line of code that I can
paste in to Xcode?
e.g. the equivalent of

int a = 1, b = 2, c;
c = a+b;

I really can't find anything on the net that applies to the Mac. (and
the most recent post here seems to be pre Xcode)

Thanks

Steve
Paul Russell - 29 Apr 2007 10:25 GMT
> Hi,
>
[quoted text clipped - 9 lines]
> I really can't find anything on the net that applies to the Mac. (and
> the most recent post here seems to be pre Xcode)

The easiest way to do this kind of thing is take you little bit of C
code and compile it with gcc -S.

Paul
Jens Ayton - 29 Apr 2007 14:31 GMT
Paul Russell:
> Steve555:
>>
[quoted text clipped - 9 lines]
> The easiest way to do this kind of thing is take you little bit of C
> code and compile it with gcc -S.

Or, equivalently, Build->Show Assembly Code in Xcode.

Signature

Jens Ayton

Steve555 - 29 Apr 2007 14:55 GMT
> Paul Russell:
> > Steve555:
[quoted text clipped - 15 lines]
> --
> Jens Ayton

Thanks, doing that produced:

void    MyAdd()
{
    int a=7, b=8;
    int c = a+b;
}

...
LBB3:
    .stabd    68,0,14
    li r0,7
    stw r0,32(r30)
    li r0,8
    stw r0,28(r30)
    .stabd    68,0,15
    lwz r2,32(r30)
    lwz r0,28(r30)
    add r0,r2,r0
    stw r0,24(r30)
LBE3:
LBE2:
    .stabd    68,0,17
    lwz r1,0(r1)
    lwz r30,-8(r1)
    blr
...
(and a stack of stuff that looks like it's not related to the tesk at
hand)

But how would I now use these instructions directly in my source? Is
there a compiler message to tell it that what follows is assembly and
not any flavor of C?
Gregory Weston - 29 Apr 2007 17:43 GMT
> > Or, equivalently, Build->Show Assembly Code in Xcode.
>
[quoted text clipped - 3 lines]
>
> But how would I now use these instructions directly in my source?

You would search via Google for XCode and asm and one of the first hits
you would find would tell you how to activate support for assembly
blocks and how they're formatted.

<http://developer.apple.com/documentation/DeveloperTools/Conceptual/Movin
gProjectsToXcode/migration_differences/chapter_2_section_14.html>

If you don't mind me asking, is there a reason you don't trust the
compiler to generate code at least as well as you for the task at hand?
Jens Ayton - 29 Apr 2007 18:02 GMT
Gregory Weston:

> If you don't mind me asking, is there a reason you don't trust the
> compiler to generate code at least as well as you for the task at hand?

Reading back, I get the horrible feeling he's trying to use GAs to generate
asm. Don't do that -- you might build Skynet by mistake.

Signature

Jens Ayton

Steve555 - 29 Apr 2007 18:32 GMT
> Gregory Weston:
> >
[quoted text clipped - 6 lines]
> --
> Jens Ayton

Hey Jens, gimme a break, old though I am, I still find this stuff
fun. ;-)
Steve555 - 29 Apr 2007 18:12 GMT
> > > Or, equivalently, Build->Show Assembly Code in Xcode.
> >
[quoted text clipped - 13 lines]
> If you don't mind me asking, is there a reason you don't trust the
> compiler to generate code at least as well as you for the task at hand?

Thanks for the link. First hit if you knew asm meant assembly.
I'm chopping up my code in to 'genes' for mutation/crossover  -a la
genetic algorithm - I just wanted to see if I could reduce the
building blocks to the smallest possible size (...without trying to
figure out what a function call looks like in binary). It's starting
to look way too scary though. I think I'll use function pointers
instead.
(No intention of competing with Xcode's amazing abilities!)

Steve
Sherm Pendley - 29 Apr 2007 18:34 GMT
> I'm chopping up my code in to 'genes' for mutation/crossover  -a la
> genetic algorithm - I just wanted to see if I could reduce the
> building blocks to the smallest possible size (...without trying to
> figure out what a function call looks like in binary). It's starting
> to look way too scary though.

If it's not looking scary enough yet, consider universal binaries, and
the fact that there are a *lot* of PPC Macs still out there. Are you fluent
in *two* different asm languages? :-)

sherm--

Signature

Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net

Steve555 - 30 Apr 2007 08:15 GMT
> > I'm chopping up my code in to 'genes' for mutation/crossover  -a la
> > genetic algorithm - I just wanted to see if I could reduce the
[quoted text clipped - 11 lines]
> Web Hosting by West Virginians, for West Virginians: http://wv-www.net
> Cocoa programming in Perl: http://camelbones.sourceforge.net

Yes, quite. Idea banished.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.