c - matrix multiplication in ARM assembly -
a course of arm assembly started @ university, , or assignment create nxm * mxp matrix multiplication programm, called c code.
now have limited knowledge in assambler, i'm more willing learn. know this:
- how read/pass 2d arrays c asm?
- how output 2d array c?
i'm thinking, can figure rest of out myself, these 2 points find difficult.
i using arm assembly on qemu, on ubuntu code, it's not going on particular device.
c arrays merely pointers, when pass c array argument assemply function, pointer area of memory content of array.
for retrieving argument, depends on calling convention use. arm eabi stipulates that:
the first 4 registers r0-r3 (a1-a4) used pass argument values subroutine , return result value function. may used hold intermediate values within routine (but, in general, between subroutine calls).
for simple functions, them, should find pointer array in r0 r4 depending on function signature. otherwise, find on stack. technique find out abi disassemble object file of c code calls assembly function , check prior calling assembly function.
for instance, on linux, can compile following c code in file called testasm.c
:
extern int myasmfunc(int *); static int array[] = { 0, 1, 2 }; int mycfunc() { return myasmfunc(array); }
then compile with:
arm-linux-gnueabi-gcc -c testasm.c
and disassembly with:
arm-linux-gnueabi-objdump -s testasm.o
the result is:
testasm.o: file format elf32-littlearm disassembly of section .text: 00000000 <mycfunc>: 0: e92d4800 push {fp, lr} 4: e28db004 add fp, sp, #4 8: e59f000c ldr r0, [pc, #12] ; 1c <mycfunc+0x1c> c: ebfffffe bl 0 <myasmfunc> 10: e1a03000 mov r3, r0 14: e1a00003 mov r0, r3 18: e8bd8800 pop {fp, pc} 1c: 00000000 andeq r0, r0, r0
you can see single-parametered function myasmfunc
called putting parameter register r0
. meaning of ldr r0, [pc, #12]
"load r0
content of memory address @ pc+12
". pointer array stored.
Comments
Post a Comment