Assembly class HERE

Re: Assembly class HERE

Postby DonQuichotte » Mon May 30, 2016 10:54 am

Nice to see you again Olaf :)
I posted from the library and there was an unexpected strike, so my hurry last day... :D welcome in France ;) the quoted URL is fine now.

I read here and there that with RISC the burden is to be taken by the programmer.
However for Epiphany there are no many conventions, search ABI or EABI under the forum or the docs - the architecture manual is a must.
From my memory I get:
r0-r3 = parameter passing ; if more than 4 parameters, it uses the stack
r0-r7 = allows 16-bit instructions (see how in one of the final tables in the arch. manual)

r32-r63: caller saved - well suited for leaf functions, iirc. Use as you like.
r63 may be used for the immediate value -1 (0xFFffFFff): it's handy for mask/bit/integer operations. Compile with -m1reg-r63 for use - it works :)
I did not try r43 that does the same but in my opinion it shoud be obsoleted, it's double usage.

r28-r31: for immediate values, reserved... not clear for who, maybe a future Adapteva use ? In my current attempt I use them for my own wanted immediate values.
r16-r27: free to use.

r8-r15 may give issues, use them in last resort. Callee saved iirc.
r8: nothing particular
r9-r10: used by the system for stack base... seen in objdump, init. part. I avoid them.
r11/r15: there is a change in the ABI, it might be "fp"... I avoid them too, I'm not fully 2016.3.1 yet.
r12: lr = Link Register, very important. You must save it for recursive functions.
r13: sp ? Basically I sub sp, some_value then ldr/str - there is no push/pop - then I add sp, some_value... saving lr and using jalr when using recursivity.
JALR is like a "CALL eax", but it's *your* burden to save the LR.
JR is like a "JMP eax", so you can use it iff the return address is guaranteed unique and you know it
RTS looks like RET but actually it's converted to "JR LR" iirc (you should objdump this for clarity)
r14: ?
ysapir's advice is good, compile and objdump:
I made the small C program recurse.c for that.

I use prefixes to alias the register and to better remember/read what I code:
I_* for Immediates
O_* for fixed Offsets
P_* for Pointers (my new habit, sometimes the Offsets should be adjusted)
R_* for Register values for the fastest possible access: crucial recurrent values
S_* for Stackable, very important to align to even registers for 64-bit values

In short: for a start objdump recurse.c or any tiny C program ; gcc-explorer is a must-have tool too: you dynamically test the code you want :D
User avatar
Posts: 46
Joined: Fri Apr 29, 2016 9:58 pm


Return to Assembly

Who is online

Users browsing this forum: No registered users and 2 guests