How to pass a long long typed parameter when calling a function c from a hand node?

I have a C function that looks like this:

int foo(int a, long long b); 

I'm trying to call it from a hand assembly, but I don't know how to deal with the second parameter ( long long ).

+4
source share
3 answers

ARM EABI / AAPCS indicates that 64-bit types should be transferred in 2 registers that are next to each other, and the first register should be even numbered. In the small end mode, the high part is in the register with a higher number, while the lower part is placed in the omitted numbered one. In big end mode, it's the other way around.

Both requirements must contain strd / ldrd instructions, which can store two registers in one instruction.

So, to pass 0x0123456789abcdef for your example in the small end mode, you need to load the registers as follows:

 mov r0, a // R1 is unused ldr r2, =0x89abcdef ldr r3, =0x01234567 
+3
source

(Beware: the answer is incorrect, you cannot delete it because the comments contain information)

According to ARM ABI, the second parameter is passed to the registers r1 and r2 . If your car is insignificant, skip the bottom to r1 and the top to r2 (I don't know if this is the opposite for big end machines). Therefore, to call a function with a parameter, for example. 0x123456789abcd:

 MOV r0, ... (the value of "a") MOV r1, #0x6789abcd MOV r2, #0x12345 ... (call the function) 
0
source

Just ask the compiler what he will tell you everything ...

 int foo ( int a, long long b ); int bar ( void ) { return(foo(0xAABB,0x1122334455667788LL)); } 

I prefer to compile and then disassemble rather than compile in asm, it is easier to read.

 arm-none-eabi-gcc -c -O2 fun.c -o fun.o arm-none-eabi-objdump -D fun.o fun.o: file format elf32-littlearm Disassembly of section .text: 00000000 <bar>: 0: e92d4008 push {r3, lr} 4: e59f001c ldr r0, [pc, #28] ; 28 <bar+0x28> 8: e28f3010 add r3, pc, #16 c: e893000c ldm r3, {r2, r3} 10: ebfffffe bl 0 <foo> 14: e8bd4008 pop {r3, lr} 18: e12fff1e bx lr 1c: e1a00000 nop ; (mov r0, r0) 20: 55667788 strbpl r7, [r6, #-1928]! ; 0x788 24: 11223344 teqne r2, r4, asr #6 28: 0000aabb ; <UNDEFINED> instruction: 0x0000aabb 2c: e1a00000 nop ; (mov r0, r0) 

and the answer r0 contains the first parameter, r1 is skipped, and r2 / r3 contains a long long one.

0
source

All Articles