Presentation is loading. Please wait.

Presentation is loading. Please wait.

Passing by-value vs. by-reference in ARM

Similar presentations


Presentation on theme: "Passing by-value vs. by-reference in ARM"— Presentation transcript:

1 Passing by-value vs. by-reference in ARM
C code equivalent assembly code int a; section ".bss" @ .bss since a is not assigned an a: .skip @ initial value; alloc 4 bytes .section ".text" int subr(int); global main int main(void) main: { push {r4, lr} a = 0; ldr r4, =a @ a = 0 a = subr( a ); mov r2, #0 return 0; str r2, [r4] @ } ldr r0, [r4] @ call subr( a ); pass “a” by value bl subr str r0, [r4] @ a = return value from subr in r0 mov r0, # @ return value 0 put in r0 pop {r4, lr} bx lr @ put lr in pc

2 Passing by-value vs. by-reference in ARM
C code equivalent assembly code int sub( int x ) subr: add r0, r0, # @ return value = x + 1 { bx lr return( x + 1 ); }

3 Passing by-value vs. by-reference in ARM
C code equivalent assembly code int a; section ".bss" @ .bss since a is not assigned an a: .skip @ initial value; alloc 4 bytes .section ".text" int subr(int *); global main int main(void) main: { push {r4, lr} a = 0; ldr r4, =a @ a = 0 a = subr( &a ); mov r2, #0 return 0; str r2, [r4] @ ldr r0, r @ call subr( a ); pass “a” by ref bl subr str r0, [r4] @ a = return value from subr in r0 mov r0, # @ return value 0 put in r0 pop {r4, lr} bx lr @ put lr in pc

4 Passing by-value vs. by-reference in ARM
C code equivalent assembly code int sub( int *x ) subr: { ldr r1, [r0] @deref parameter return(*x + 1); add r0, r1, # @return val in r0 } bx lr


Download ppt "Passing by-value vs. by-reference in ARM"

Similar presentations


Ads by Google