Below are some useful macros in NASM for ARM ("narmw"), if you have some ideas or hints to help me develop software for PalmOS5 , I'll be glad to hear them.
I noticed NARM is actually almost as powerful as MASM, and only the lack of "%xdefine" in narmw keeps me from building an OOP framework for arm. If/when I return to x86, I will try to port ATC to nasm :)



Example:
proc test4,var1,var2,var3,var4,var5,var6,var7,var8
local var9,var10
add var1,var1,var2
add var1,var1,var3
add var1,var1,var4
add var1,var1,var5
add var1,var1,var6
add var1,var1,var7
add var1,var1,var8

ret ; var1 = r0
endp




%macro proc 1-*
%1:
%rotate 1

stmdb sp!, {r4,r5,r6,r7,r8,r9,r10,r11,r12,r14}

%if %0>1
%define %1 r0
%endif

%if %0>2
%define %2 r1
%endif
%if %0>3
%define %3 r2
%endif
%if %0>4
%define %4 r3
%endif
%if %0>5
ldr r4,[sp,#40]
%define %5 r4
%endif
%if %0>6
ldr r5,[sp,#44]
%define %6 r5
%endif
%if %0>7
ldr r6,[sp,#48]
%define %7 r6
%endif
%if %0>8
ldr r7,[sp,#52]
%define %8 r7
%endif
%if %0>9
ldr r8,[sp,#56]
%define %9 r8
%endif
%if %0>10
%error Too many parameters
%endif

%endmacro


;proc ilko , var0,var1,var2,var3,var4,var5

%macro ret 0
%ifdef this_proc_locals
%if this_proc_locals
add sp,sp,this_proc_locals*4 + 4
%endif
%endif
ldmia sp!, {r4,r5,r6,r7,r8,r9,r10,r11,r12,r15}
%endmacro

%define endp


%macro local 1-*
%ifdef this_proc_locals
%if this_proc_locals
%error Locals already created!
%endif
%endif
%assign this_proc_locals 0
%rep %0
%if this_proc_locals = 0
%define %1 [sp,#0]
%elif this_proc_locals = 1
%define %1 [sp,#4]
%elif this_proc_locals = 2
%define %1 [sp,#8]
%elif this_proc_locals = 3
%define %1 [sp,#12]
%elif this_proc_locals = 4
%define %1 [sp,#16]
%elif this_proc_locals = 5
%define %1 [sp,#20]
%elif this_proc_locals = 6
%define %1 [sp,#24]
%elif this_proc_locals = 7
%define %1 [sp,#28]
%elif this_proc_locals = 8
%define %1 [sp,#32]
%elif this_proc_locals = 9
%define %1 [sp,#36]
%else
%error Too many locals!
%endif
%assign this_proc_locals this_proc_locals+1
%rotate 1
%endrep

sub sp,sp,this_proc_locals*4 +4

%endmacro



; GetWordElement(r0,table1,r1) = mov r0,table1[r1*2]

%macro GetWordElement 3
add %1,r15,%3,lsl #1
ldrh %1,[%1,%2-%%this]
%%this:
%endmacro



Also, I found out that I should disasm libgcc.a to clone+modify __divsi3 , since if I divide on 0, my program really misbehaves.
Anyone else here coding ARM ?
Posted on 2004-05-29 18:00:28 by Ultrano
I tried to before, but because of time restrictions I cant, but I used VisualHAM tho since the ARM7 I'm using is in my GBA and I have a flash cart too :D. Programming ARM is fun!
Posted on 2004-05-29 19:50:00 by x86asm
I did some ARM optimizations for the ARM7TDMI (memory operations, blit, YUV -> RGB conversion, ...) The performance boost was decisive. I used a package with a GCC arm compiler and a GBA emulator for debugging. The GBA emulator was very useful because the video format is RGB 555 and I was working on a system with RGB 565. ARM7 optimization is easier than PC optimization : no cache, simple pipeline, lots of registers, conditionnal execution for all instructions...
Posted on 2004-05-30 01:01:51 by Dr. Manhattan
Hi x86asm, do u have any interest in making an ARM plugin for ProEmulator?
Maybe u can join my project on sourceforge (by becoming a developer member), what do u say?


I tried to before, but because of time restrictions I cant, but I used VisualHAM tho since the ARM7 I'm using is in my GBA and I have a flash cart too :D. Programming ARM is fun!
Posted on 2004-05-30 05:49:22 by optimus

Hi x86asm, do u have any interest in making an ARM plugin for ProEmulator?
Maybe u can join my project on sourceforge (by becoming a developer member), what do u say?


I would love to but the next CPU I was going to tackle was the Motorola 68000 ( so I can write Sega Genesis emu)! I'll decide which CPU is better for me to emulate and get back to ya :D
This is assuming you dont mind a Motorola 68000 emu in ur project :D
I'll assess the ARM CPU's instruction set (ARM7 u want?), I might detour from 68000, if I can write the ARM7 by hand instead of coding a C asm outputter (the case for my 68000 emu)
Posted on 2004-05-30 21:01:26 by x86asm
Any new CPU to be implemented in ProEmulator is welcomed! If u can implement a 68k cpu, perhaps ProEmulator will be able to emulate a MAC someday and that seems pretty cool. ^_^
If time permitted, i will try to write an ARM7 emulation plugin (if feasible i'm thinking of adopting Dynamic Binary Translation technique), maybe we can co-operate to finish the work.
Posted on 2004-05-31 06:56:08 by optimus

Any new CPU to be implemented in ProEmulator is welcomed! If u can implement a 68k cpu, perhaps ProEmulator will be able to emulate a MAC someday and that seems pretty cool. ^_^
If time permitted, i will try to write an ARM7 emulation plugin (if feasible i'm thinking of adopting Dynamic Binary Translation technique), maybe we can co-operate to finish the work.

I am definitely more than willing to help co-op on the ARM7 emulation, but the thing is that I havent researched Dynamic Binary Translation that much so I'm not very knowledgable on the subject I will do some research in my spare time. I will forge ahead with the Motorola 68000 emulation, I started that project about a week ago. (Still fixing bugs in the Z80 CPU emu as well tho too)

Sorry for crapping on ur thread Ultrano. :(
Posted on 2004-05-31 15:41:17 by x86asm
lol np :)
Posted on 2004-05-31 15:56:00 by Ultrano
Also ATC to nasm will be interesting ;), gl and if I can help I will try.

Have a nice day or night.
Posted on 2004-05-31 23:32:55 by rea
nasm supports ARM??
Posted on 2004-06-01 09:49:44 by optimus
http://www.geocities.com/SiliconValley/Hub/6461/arm/

"what it's lacking is the object-dumper part" ...
also it lacks import of external symbols, and
blt gets translated as bl :(
It makes me think about making a macro wrapper to arm-palmos-as.exe . Actually I've just started making this wrapper.
Posted on 2004-06-01 10:51:58 by Ultrano


I am definitely more than willing to help co-op on the ARM7 emulation, but the thing is that I havent researched Dynamic Binary Translation that much so I'm not very knowledgable on the subject I will do some research in my spare time. I will forge ahead with the Motorola 68000 emulation, I started that project about a week ago. (Still fixing bugs in the Z80 CPU emu as well tho too)

Sorry for crapping on ur thread Ultrano. :(


DBT is much more harder to implement than interpreting. This will be a work to be done later. ARM interpreting emulator should be firstly implemented.
Posted on 2004-06-01 19:47:32 by optimus

http://www.geocities.com/SiliconValley/Hub/6461/arm/

"what it's lacking is the object-dumper part" ...
also it lacks import of external symbols, and
blt gets translated as bl :(
It makes me think about making a macro wrapper to arm-palmos-as.exe . Actually I've just started making this wrapper.


It sounds great.
But sorry I can never visit geocities here. Any mirrors of the site?
Posted on 2004-06-01 19:48:48 by optimus
:( no mirrors,
http://66.102.11.104/search?q=cache:Lk3DcPhOJlIJ:www.geocities.com/SiliconValley/Hub/6461/arm/+arm+nasm+assembler&hl=en
but for the files ....
anyway, it's not a perfect package, has no documentation, and pretty soon I'm sure to replace it. I've managed so far to enable basic macros and %define , currently working on proc/ret/endp , then on .if .while, @@, @F @B , ... oy :)
Posted on 2004-06-03 03:42:45 by Ultrano
I will take a look @
http://www.geocities.com/SiliconValley/Hub/6461/arm/

Interesting, I from time to time whant to help the nasm project ;) finall examinations here, but then come the vacations, hope I can do some.

Ultrano you already look at some of the macros implemented for structured programmin? I think the package of tomcat have the original ones, also I think I do "interesting" macros for proc... and such things.

Also will be interesting see how is modificated nasm for assemble arm instruction set.


Have a nice day or night.
Posted on 2004-06-05 11:44:01 by rea
I haven't seen any such macros. And when I googled on it now, I couldn't find anything completely relevant - what is Tomcat? (Apart from my favourite jetfighter F-14 :grin: ) . Structured programming ... aye it's not really clear to me - the seach on it returned stuff like "no branching" and "java", which confuses me more :) I'll look it up if I find some time
Posted on 2004-06-05 12:14:42 by Ultrano
This one is http://rs1.szif.hu/~tomcat/win32/ :) I google tomcat nasm. :).


Structured programming ... aye it's not really clear to me - the seach on it returned stuff like "no branching" and "java"


For me structured programming not mean java, C, C++ or any other, mean tht you can draw a plain graph following the secuence of instructions, and any structure for complicated that it apear to be can be draw as a plain graph and not overlap other lines on the graph, not more not less.


mmmm, also structured programming mean "not spaguetti code", also spagetti code is a not plain graph ;), and for analyse it you need other things... some things not are directly aplicable to them.

Also in electric circuits is important have a plain graph for aply the thechnique "analysis by meshes" (an?lisis por mallas).




Apart, I dont understand completely the thing about the output for arm.. the thing "what it's lacking is the object-dumper part",or "barely produce any usable output!"

Have a nice day or night.
Posted on 2004-06-05 12:44:03 by rea
lol btw, I saw the "The shortest helloworld" on TomCat's site .. omg is this to scare newbies :) ?
I'd show newbies the following working code:


include \masm32\ultrano\bank\base.inc
start:
msgbox "hello world!"
invoke ExitProcess,0

:P
Structured programming ... following only one way of coding seems to me that will produce unoptimized code. I prefer writing optimized code, AND giving complete comments on them. So far my boss and colleagues cope with that :D
hmm on second thought, I guess I've been coding the structured way :) Anyway ^^" ....that doesn't matter...
Posted on 2004-06-05 13:11:33 by Ultrano
;) scary newbie == scary movie ??

Also here are others more short
http://www.asmcommunity.net/board/index.php?topic=1469



Understand well structured programming will help (or at less that is the objetive), for example, I know people that is learning for example C, and even that they have the structures for help do structured programming (functions, "constrol structs"), they can't in fact do well structured programms, that is: that you have suport for a thing, not mean that you know how to use it that is a fault when teachers expose how to write a programm with C or other I think ... ;). Also there are people that can use it without go in dept, but they have a more clear way of how to use them. The teachers think that having "descriptive" names for the control structs the student will catch how to do things well, when that is only a suposition, for proof, you can find on internet some examples (provided by teachers or other similars) of how the students do faults: extrange comparisions or inecesary, write the same in a diferent ways and others "problems" that teachers say that the student dont understand, when in fact that is a fault of both parts... the teacher assuming that is clear and not explaining structured programming objetive and what is and the student for not question the teacher.



Also other proof that structured programming not mean C, java, C++ or any other that "implement" such constructions for help is that they can't launch errors regarded to them, in fact, they can launch errors/warnings related to: cast, mismatch in size, prototypes, class declarations, incorrect or not defined symbol, unitialized pointer, but in fact any of this can't (at less as I know) launch a error in the logic when you use while, for, etc. Then is clearly that this languages only give the structures but are not part of any of this languages, because the compiler can't launch errors about this.

In fact that type of errors regarded to structured programming is showed at execution time (the compiler can't catch them), when a guy whant x result and he/she think that the programm is running in a bad way.

sorry if I polute a little your thread.....

But like I see now, C,C++ and others reserve only that "reserved words", for/while/do/others and do a little implementation, perhaps they provide a sintaxis for use them, also can do a little about optimization, but in fact they are not part of any of this languages, because the real parts that are suported inside the languages the compiler can launch errors of them, also they have a sintaxis and reserved words, but the compiler can launch errors/warnings. With the control struct of structured programming any compiler(that I know) can launch even a warning, then I not consider that the language have a real suport for structured programming... they provide only like macros ;), the real parts of this languages are the things that dont belong to that structures.

For example (on the fly):

.....
int a = 16;
if( a > "32"){
a = a + "32";
}

The compiler will launch a error in: a > "32", a = a + "32";, but in fact, the compiler never can say you if (or questionate your logic) about:

int a = 16;
if( a > "32"){
// at less I think the assembler will
//nedd you say that It will not translate
// the block belong to if(a> "32") and
//continue pheraphs to the else... that
//will be executed anyway, because is
//not assembled the if block...


And more if is at runtime and always you get: a<someValue... the compiler can't say in what part is the error, you should debug and understand the operations that carry to always have that value in that part of memory.



But like you see I can :) questionate the logic.


Then pheraphs you or other that is reading this, can see that high level languages dont implement more than some more powerfull macros (because optimization and such things and some type checking... that in fact is regarded to the core of the language by itself) in some way, they are only separed like part of the language by means of "reserved words", but they don't belong to any language, they belong to logic in programming or a more logic way of do things, and in some way analysis of graphs, I dont know much about analysis of algorithms, but I supose that is more easy analyse a plain one that a not plain, but not plain ones also can be of help... I supose, not all is plain in this world.


Also because the language need use them, in some way is impactated the look of the language, that is: structured programming change some in the language that is traying to implement or at less provide the constrol structs for use it. But is structured programming that impact the language and not viceversa. Also see that impact the language, not mean that the language itself can understand structured programming ;).


Have a nice day or night.

For resume:
structured programming dont belong or is not well implemented in the compilers that I know, because the compiler is suposed to help you in write a programm in x language, and it should give you warnings/errors about the bad usage of the language and translate to machine target, then when I find that a x compiler can't questionate the logic of how to use a suposed part of the language (the one regarded to structured programming), then this part, because is not directly handled by the compiler, ie, it dont give me a warning, then the use of the compiler "for this part of the language" is near to nothing**, then is not a direct part of the language, because can not be handled by the suposed one that will handle the translation and correction of the programm, the compiler.


** Also see that some errors launched inside constrols structs are of the language, mismatch pointers, unitialization, etc, but not question the logic.
Posted on 2004-06-05 14:38:52 by rea