PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Assembly On iPAQ

anyone know any good resources!
At last i have anothe computer with an ARM chip in it, i want to play with all my old code from my Acorn days:)
Ta
Ta thanks for that,
I'm DLing eVC++ atm, does that support inline assembly? and if so do u know any good tutorial sites for it
ta :)
No, the StrongARM compiler included with eVC++ does not support inline assembly. :(

Dan East
O
What tools do you use for deving in assembly then. I have seen peeps in other threads talking about developing in Assembly.
ta
:)
eVC includes macro assemblers for the various Pocket PC processors.
You just create an asm file which is pure assembly, and assemble it into an object file with ARMASM.exe. Then you link that object file in with the rest of your modules to build your app.

Dan East
Thanks for all the info
V excited about playing with ARM code again
:)
nice site btw

No one here has any experience with actually using ASM for the iPaq, as far as I know. So I would be very grateful if you could document your first steps. :)
ok
1.) Dan East have you not used armasm in your port of quake? if so any samples would be good

2.) MSDN has incomplete info on armasm and no samples (that i could find), so anyone else reading this that has examples or knows were some are, please post.

ta ra
:)
No, I've not used ARM assembly. You can get the ARM C++ compiler to generate .asm files from your C source. That would be a good way to start. I assume those files will assembler with armasm.

Add the /FA option to the "Project Options" edit box under the C/C++ tab in Project Settings, and when you build you'll find .asm files in your output dir.

Dan East
Okay, this worked fine for me:

Added the /FA option so .asm listings were generated for all my C/C++ source files.

Built the project.

Deleted the .obj file for a particular source, "mysource.obj".

Rebuilt that .obj file by running "armasm.exe mysource.asm".

Hit F7 and the linker relinked using my new .obj file I assembled manually.


So what I recommend is to prototype what you want to do in assembly in C. At least create the placeholder functions in C. Then edit the .asm file manually to optimize, etc. Now, the important part is to remove that C source file "mysource.c" from the list of Source Files in the FileView tab of eVC++. If you don't do that, then the next time you build your mysource.asm file will be overwritten, which would not be cool. :)

I have used the /FA option before so I could compare various C / C++ implementations to see which was more effecient.

Dan East
That’s excellent just the tip I need!!!!
Out of curiosity? If there is no assembler used in the quake port, how are the graphics drawn? Surely the code that rasterizes the geometry and stuffs numbers into the screen mem is not written in c/c++(blimey maybe I am old school :(  )?
Anyway I have a simple API that I wrote (100% assem) for the Acorn that did this stuff, my first project( in the new year) will be to get this working although its slightly reinventing the wheel (with pocketGL about), but its much more low level than GL(simple but bloody fast) and will give me a good opportunity to play with eVC, armasm, pocketPC and GAPI.
I will document my efforts and post the results here :)
laters and ta for advice
Soz i was not being critical of port:)
out of interest to you, the ARM has a great barral shifter that can logicaly or arithmetically shift one of the source registers left or right e.g.
ADD R0,r1,r2 LSL#16 // r0=r1+(r2<<16) only one clock tick!

This is fantastic for fixed point maths. It would be interesting to see if the eVC compiler identifies this in your fixed point maths and does not produce two instructions where one would do. If you have tight loops of only a few instructions this could be a significant performance gain.
laters
:)

No assembly is used in the Pocket Quake port. Even worse (far, far worse), Quake's 3D engine relies almost exlusively on floating point math, which no Pocket PC hardware supports natively. I have converted some floating point routines to fixed point, and have increased FPS almost two-fold so far. The conversion to fixed point math is of far greater importance than assembly at this point.

Dan East

Last modification: Dan East - 12/12/01 at 09:11:49
I've done quite a bit of ARM assembly language programming.  If you have questions that the ARM reference docs can't answer, feel free to ask me.

I was thinking, would it be possible to write a simple preprocessor for .cpp files that finds inline assembly in comments, like:

Code:

/* _ASM
MOV EAX, 10 // or the ARM equivalent :)
_ENDASM */


The inline assembly could then be exported to a single .asm file, assembled, added to the project and so on, so that basically the whole process is transparent and you end up with something that looks like inline assembly... That would be cool. :)

Another option might be to make a runtime compiler, that accepts mnemonics:

assemble( "MOV EAX, 0" );

and returns a function pointer. You could perform the assembling step during initialization, and once again you would have more or less inline assembly.

Are there any Open Source ARM assemblers available?

- Jacco.
Good idea, but there could be some problems. Each section of assembly would have to become its own function, because it will reside in a seperate object file from that of the parent C source. However, you could just inline the function definition, so the code should be inserted in place. However, could you access the local C vars from within your ASM since it resides in a seperate obj file? When a function is inlined is there extra overhead to prepare the stack, registers, etc? That may negate the performance increase the assembly gained.

Dan East
Dan as far as I know, the compiler can't inline assembly language functions.

I really wasn't thinking. You can't inline extern funcs regardless. :(

Dan East
the preprocessor approach only would work for full functions, and if you do that you might as well do it in a fully separate file

what however would be interesting is to see if we can somehow make vce compile .asm files automatically with a pre build step or something, that would be sufficient and convenient enough for all my needs

I'll look into it and post my findings :-)

Kind regards,
Willem
Getting eVC to automatically assemble your .asm files is easy.  Add the .asm files to your list of source files in the project, then create a custom build step.  I've done this for years.  Let me know if you have trouble and I'll post the details.
thought it would be something simple like that

sweet, all my asm needs are forfilled :-)
Answering my own question
The eVC compiler does not optomise for shifts on source rgisters when compiling ARM code
a=b+(c<<8)
compiles to:
mov r1, r2, lsl #8
add r3, r0, r1

As opposed to:
add r3,r0,r2 lsl #8
hmmm bad Microsoft :(
BTW
it would not be too difficult to go through by hand and correct this by hand for anyone doing an amount of fixed point maths thats using alot of shifting.
The same is true for the indexd addressing on LDR/STR
LDR r0,[r2,r3 lsr #2]
omg im sad but i just love the code.
How would you go about correcting this by hand?  Since the ARM compiler shipped with eVC doesn't support inline assembly language, you'll have to write a function to do this in a separate .asm file.  The function overhead would negate any win you'll get.  The only way to get the speed up you're talking about is to code the entire function that uses fixed-point in assembly language.  Or perhaps you could munge the .obj (yikes)?
simonjacobs · 19 Dec 2001, 17:42 UTC
But couldnt you compile your c/c++ to asm, edit the asm file, then compile to machine code?

Of course, it is more effort to do that :)

It depends how much speed you want I suppose.
Simon,

Certainly you could do that.  However, everytime you changed anything in the C version of that function you'd have to go back and do it again.  That's not something I'd want to do.

simonjacobs · 19 Dec 2001, 19:32 UTC
Good point. I suppose you could do assembly optimization as the last stage of the project but it's hardly ideal either way. An inline assembler would come in handy!

btw. of this discussion, I have question..
How looks case of branch delay slots on StrongARM? Do I have to care about that when coding in assembler, like on MIPS or Sparc?

tia.
No.
The point of these optimisations is that they are acaemic, i come from an age of 4mhz ARM 2 processors where saving a handfull of instructions per frame was very important, The extra development time to manage this kind of development would not get pass the accountants today! I just love messing with code. I hope most peeps here do to.

BTW
Gruk you don't have to worry about branching as a technical issue, but it does flush the pipe (it did anyway, ARM may now have changed that) so you will/did loose a few cycles filling it again which makes it a bit inefficient for very tight loops.
laterz
:)Last modification: Mole - 12/20/01 at 03:28:14
Hey guys. I just figured out a way to do inline assembly with ARM. I've not tested this, because I don't have time to write the tiny extra program that is required. But here's the technique:

1) Add the /FAs compiler flag to your C/C++ Project Options. That causes the compiler to produce an ASM listing for each source file, PLUS includes the original C/C++ source listing in the asm file as comments.

2) In your C/C++ source use a predefined dummy function call to indicate where you want to start inlining. The reason this is needed is to indicate exactly where in the output asm the inline asm is to be inserted. _asm() is a good choice.

3) Immediately after the _asm() call place a comment block which contains your asm. Something like this:
[fixed]
int i=0;
_asm( ) ;
/*
 {
   mul       r8, r3, r6
   ;This is my asm comment
   mov       r3, r8, asr #5
   and       r7, r3, #0x3E, 22
 }
*/
[/fixed]
4) Now for the part that makes this work. A simple program is executed as a custom build step. It simply scans the .asm file looking for calls to the _asm() function. When one is found, it modifies the asm as follows:

a) Comment out the actual call to _asm, including any stack / register stuff done before / after the branch.

b) Uncomment out the block of asm the user has in their comments. This would be the lines within the /* {   } */ block.

c) Then your custom program calls armasm, and rebuilds the asm file, which now includes your inline asm code.

The main caveat is that it is critical that the comments that contain the inline asm fall immediately after the jump to the _asm() routine. The custom program might should check for that, and bump the inline asm up if need be. A quick test showed that comments after a function call do appear directly after the branch. However, there may be cases when the compiler sticks other asm before the comments, so that needs to be taken into consideration.

Dan East

[color=blue][sup]Last modification: Dan East - 12/20/01 at 06:39:21
Very cool. That leaves us with just one problem: Addressing variables used in the C code... Any ideas how we could pass data to the asm at all? Perhaps we can extract variable addresses using the simple preprocessor that you mentioned?
Assembler is like Oracle, a right bugger to work with, but very good once its working! :)
you could just wrtie the whole of ur app in notepad using assembler, then there would be no need for this messing about with C!

BTW pocketmatrix dudes whens the developer section of the site going to open?
later
:)
You're right. The arm compiler assigns vars to registers and doesn't even hint at their association. So, that really compromises the usefulness of this add-on inline assembly.

Digby, is the } character valid / ever used in ARM ASM statements?

Dan East
Yes it is on multi register loads
LDMIA r12,{r1,r2,r3,r4}
soz
Jacco, you can get the compiler to do this with little trick.  The first 4 function parameters are passed in R0..R3.  If you pass these variables to your dummy function, then you'll know what registers they will be in before the call.

_asm(foo, bar);
/*
;R0 = foo
;R1 = bar
*/

Another problem. It appears it is not guaranteed that the compiler will output every line of source to the asm file. During the optimization phase it must omit portions of the source. In this example:
[fixed]
void f() {
 _asm();
 /* {
 add r1, r2
 div r1, r2
 }*/
}
[/fixed]
the compiler does not dump the commented lines to the asm file. However, if I include meaningful C code underneath the inline section (that will not get opimized out), then the comments go through.

I have the preprocessor done. I need to have it call the arm assembler on the modified asm file, which is a trivial step.

Dan East
Digby, that's excellent - and provides another practical use for the dummy function. However, I want to have the preprocessor (for lack of a better term - it is actually a pre-link processor) strip out any registry / stack stuff before the _arm() function. The assembler has to copy those vars into the registers immediately before the inline code, correct? So we still aren't going to be as effecient as inlining natively supported by the compiler.

Another question. Exactly what opcodes are called before / after a branch/link to prepare the registers, etc? I looks like stmdb is used to save registers / stack state. Which of those would be needed to set r0-r4, and which should be removed relating to the stack?

Dan East
CE currently only supports the _cdecl calling convention which means the caller is responsible for doing any clean up associated with the call, however in your case the caller shouldn't be doing anything but loading registers prior to making the call to your dummy function, provide that you don't pass more than 4 parameters.  The compiler should emit a BL instruction to call your routine.  If the function returns a value, it comes back through R0.

More info on this can be found in the eVC Docs under Microprocessor Reference/ARM/ARM Calling Standard.



Good luck guys.  Personally, what I think you're trying to do is overkill and will probably end up costing you more than you'll gain.  However, it is interesting to see your approach to working around a compiler limitation, and I'll contribute info when I can.

I've thought about doing something similar to this months ago to generate blocks of assembly code at run-time for the inner loop of a rasterizer, depending on what render states were set for the polygons. In the end, I just hand-optimized a few of the more popular cases, and the others have tests in the inner loop.

Oh a few other things: The latest version of the ARM compiler from MS still doesn't support inline assembly and probably never will.  So that means if you guys get something to work, it won't be meaningless when Talisker releases next month.  Did you know that everytime you use inline assembly on the x86 compiler, the compiler disables optimization for that entire function?  That means none of the C/C++ code in the funtion will be optimized.  That, very often, is not a good thing.

Digby,

For me the main reason to want an inline assembly thingy is the way I develop assembly code: Usually I start with some good C code, then I prepare the C code for conversion to asm, then I convert some portions and test wether or not the whole thing still works. This is where inline assembly comes in handy: I can convert code line-by-line, wich is a Good Thing. Once the entire function is converted, it can be moved to a separate .asm file of course, but even then, if it's one of the members of a class, I would rather have it in the same source file as the rest of the methods.

But the line-by-line conversion is what I really need it for. And if Dan's approach means it's going to be a bit slower than a pure asm file, so be it. BTW, I doubt that it will be significantly slower. If I draw a 64x64 sprite with alpha blending, I expect a huge gain from asm. 8 assignments (4 to load the registers, 4 to restore them) will not undo that advantage.

- Jacco.