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.
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.
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
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
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
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!
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.
... 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
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
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.
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.