Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 06-26-2011, 02:26 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 2
tango is on a distinguished road
Default Assembler?

I am new to the iPhone/iPad development platform, but is there any way to compile assembler code on the iPhone/iPad? I have some code that is already running on desktop platforms written in assembler that I would like to run on the iPad, and am looking for a way to do this while still having optimal access to the dual cores.

Last edited by tango; 06-26-2011 at 10:19 PM.
tango is offline   Reply With Quote
Old 06-26-2011, 06:16 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

Well, the first question to address would be:

What desktop system are you using that has an ARM v7 compatible instruction set?
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 06-26-2011, 06:22 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2011
Location: South Florida, US
Posts: 357
lgehrig1 is on a distinguished road
Default

Compile "on" the iPhone/iPad or compile "for" iPhone/iPad? Big diff, because Apple kinda frowns on the "on".

For the "for" part - I'm a tad confused. What, exactly, have you tried? I figure you could either use the _asm for inline, or just throw everything into a static library and link it in (obviously anything PowerPC ain't gonna fly). So where exactly are you having trouble?

Also - you do know the iPads and iPhones are running variants on ARM, yes? Unless you're intimately familiar with those chips, their strengths and limitations, I'd suggest just sticking to C/C++. If you're doing something wonky check out the Accelerate framework to speed up math and DSP-style calculations. It's already optimized and works across the A4 & A5 plus whatever else comes out.
lgehrig1 is offline   Reply With Quote
Old 06-26-2011, 10:36 PM   #4 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 2
tango is on a distinguished road
Default

Quote:
Originally Posted by dljeffery View Post
Well, the first question to address would be:

What desktop system are you using that has an ARM v7 compatible instruction set?
Sorry for my misleading first post. I have code running in Windows that I am in the process of converting to x86 assembly. It's written primarily in Python (which I really do not like), but has elements of it that I wrote in C. Although I have not tested this yet, I imagine that my code would also run directly on my Macbook. I am new to assembly language, but learning a lot!

Converting to assembly is two-fold. First, I am speeding up my code by optimizing my algorithms and only performing operations that need to be performed (fine tuning), and two is that I am learning more about how these computers and devices work.

What I am curious about, is if my code, written in assembly, will be efficient enough to be able to be run directly on the iPad, or if I need to use the iPad as a window or remote interface into another, more powerful, computation machine (which I would like to avoid).

Quote:
Originally Posted by lgehrig1 View Post
Compile "on" the iPhone/iPad or compile "for" iPhone/iPad? Big diff, because Apple kinda frowns on the "on".
Compile for the iPad.

Quote:
Originally Posted by lgehrig1 View Post
For the "for" part - I'm a tad confused. What, exactly, have you tried? I figure you could either use the _asm for inline, or just throw everything into a static library and link it in (obviously anything PowerPC ain't gonna fly). So where exactly are you having trouble?
I haven't tried anything yet. It's just an idea that I've had floating around my head that I wish to explore. To be honest, I know very little about developing for the iPad, although I do know that I like to use it.

Quote:
Originally Posted by lgehrig1 View Post
Also - you do know the iPads and iPhones are running variants on ARM, yes? Unless you're intimately familiar with those chips, their strengths and limitations, I'd suggest just sticking to C/C++. If you're doing something wonky check out the Accelerate framework to speed up math and DSP-style calculations. It's already optimized and works across the A4 & A5 plus whatever else comes out.
No, I am not intimately familiar with the ARM (or it's variants). While I like C/C++, I prefer to have the nitty-gritty control over what the chip is doing with my numbers. I am also curious about assembler, and want to know what the limitations of the iOS platform are!

Thanks for your help!
tango is offline   Reply With Quote
Old 06-26-2011, 10:59 PM   #5 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

Well, you're going to need to learn Objective C at any rate. I'd start there, and then considered optimizing after you identify performance issues.

I believe that ARMv7 assembly should be significantly different from
x64 assembly. So there's another reason to do the assembly code later, not sooner.
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 06-27-2011, 10:29 PM   #6 (permalink)
Registered Member
 
Join Date: Jan 2011
Location: South Florida, US
Posts: 357
lgehrig1 is on a distinguished road
Default

Quote:
Originally Posted by tango View Post
... First, I am speeding up my code by optimizing my algorithms and only performing operations that need to be performed (fine tuning) ...
That's like 99% of the boost you're going to get. I think you're really underestimating modern compilers.

Quote:
Originally Posted by tango View Post
While I like C/C++, I prefer to have the nitty-gritty control over what the chip is doing with my numbers ...
But you don't. iOS and Mac OS/X are preemptive multi-process / multi-threaded operating systems. At any moment whatever code is running can get interrupted and trashed. With the address translation kicking in, your nicely lined up array is actually spread all over memory (and disk) like violent blood spatter. Heck, you still get page faults when nothing has left memory - the OS decided it wanted that patch of memory, took it, and left your program crying!

Personally - let the compiler unroll your loops. Use C++ template meta-coding to build your constant arrays & function coefficients at compile time. Use the Accelerate framework and hook into the DSP chips already baked in.

Unless you're working on a linker. In which case, yeah, you're absolutely going to need to nerd-up on the processor architecture
lgehrig1 is offline   Reply With Quote
Old 06-28-2011, 12:19 AM   #7 (permalink)
Registered Member
 
headkaze's Avatar
 
Join Date: Feb 2010
Posts: 359
headkaze is on a distinguished road
Default

Using the VFP / Neon might be the only time to use asm.

Check out this presentation.
__________________
Headsoft | Jungool
headkaze is offline   Reply With Quote
Old 07-03-2011, 02:09 PM   #8 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by tango View Post
Sorry for my misleading first post. I have code running in Windows that I am in the process of converting to x86 assembly. It's written primarily in Python (which I really do not like), but has elements of it that I wrote in C. Although I have not tested this yet, I imagine that my code would also run directly on my Macbook. I am new to assembly language, but learning a lot!

Converting to assembly is two-fold. First, I am speeding up my code by optimizing my algorithms and only performing operations that need to be performed (fine tuning), and two is that I am learning more about how these computers and devices work.

What I am curious about, is if my code, written in assembly, will be efficient enough to be able to be run directly on the iPad, or if I need to use the iPad as a window or remote interface into another, more powerful, computation machine (which I would like to avoid).
You didn't hear what others have told you.

iOS and Macs/PCs use a completely different processor who's assembler is totally different, and totally incompatible. iOS runs on ARM processors, and PSs and recent Macs use 80x86 chips.

Modern Macs and Windows PCs both use 80x86 assembler. You can in theory use the same assembler code on those two platforms. I say in theory because when you work in assembler you end up having to worry about lots of tiny little details about the OS and how application code interacts with it. Different OSs have different ways of packaging code (DLLs in Windows, and framework or static libraries in Mac OS), different applications frameworks they work with, different register conventions for passing parameters between functions, etc, etc, etc.

It's really not practical to share assembler code between Mac and Windows, and is totally impossible to share assembler between iOS and either Mac or Windows. Forget it, it can't be done.

If you want to share code across platforms, use C. Write your code with an outer wrapper in Objective C for iOS that interacts with the Cocoa Touch framework, and inner code in vanilla C.

For Windows, you're outer layer code will probably be C++, and if you design it properly, the inner workings can be the same vanilla C that you use in iOS.

The C language is specifically designed to be "close to the machine". It has low-level operators and data structures that enable you to write very assembler-like code that runs very fast, but is still portable, whereas assembler is not.

Quote:
Compile for the iPad.



I haven't tried anything yet. It's just an idea that I've had floating around my head that I wish to explore. To be honest, I know very little about developing for the iPad, although I do know that I like to use it.



No, I am not intimately familiar with the ARM (or it's variants). While I like C/C++, I prefer to have the nitty-gritty control over what the chip is doing with my numbers. I am also curious about assembler, and want to know what the limitations of the iOS platform are!

Thanks for your help!
I have done quite a bit of assembler in my day. It used to be that you had to write in assembler in order to get really fast performance. However, those days are long gone. Modern processors are really, really, really fast, and modern compilers are very smart. The code generators are highly optimized for the chips for which they generate code, and written to generate very efficient machine code. You really have to know what you're doing to create hand-written assembler that's faster than the code the compiler generates. It's possible, but not trivial.

You are much, much better off optimizing your algorithms. An "n squared" algorithm (one where the time required goes up with the square of the number of elements being calculated) will still grind to a near standstill in hand written, ultra optimized assembler when the number of data elements climbs above a certain level, and a "log n" algorithm written inefficiently in a high level language will run circles around it.

If you're curious and want to learn about assembler, pick a platform and study assembler for that platform. Understand that assembler code is machine-specific.

Learning assembler is a good experience. It lets you understand what goes on "under the covers" on a machine. It will end up helping you in lots of ways. However, I don't think there's much if any applications development being done in assembler these days except for embedded systems and microcontrollers, and even some of those use higher level languages like C.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 385
18 members and 367 guests
Absentia, AyClass, Diligent, dre, givensur, hussain1982, jbro, jPuzzle, momolgtm, Newbie123, Paul10, revg, sacha1996, skog, skrew88, taylor202, tomtom100
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,643
Threads: 94,110
Posts: 402,858
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Diligent
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:44 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0