|
| 1 | +# |
| 2 | +# This function is to check if ddisasm finds a function entry after literal |
| 3 | +# pools even if there is no symbol info nor direct calls to the function. |
| 4 | +# |
| 5 | +# The function `add` does not have any direct call to it. |
| 6 | +# After stripped, `add` has no symbol information. |
| 7 | +# It is placed right after the literal pool. |
| 8 | +# |
| 9 | + |
| 10 | +.arch armv7-a |
| 11 | + |
| 12 | +.thumb |
| 13 | +.text |
| 14 | + |
| 15 | +.equ SYS_EXIT, 1 |
| 16 | +.equ SYS_WRITE, 4 |
| 17 | +.equ STDOUT, 1 |
| 18 | + |
| 19 | +@ Function: sum (calls a function via BLX r3) |
| 20 | +.global sum |
| 21 | +.type sum, %function |
| 22 | +.thumb_func |
| 23 | +sum: |
| 24 | + push {lr} @ Save link register |
| 25 | + mov r3, r2 @ Store function pointer in r3 |
| 26 | + blx r3 @ Call function pointer |
| 27 | + pop {pc} @ Return |
| 28 | + |
| 29 | +@ Print function: writes r0 as ASCII to stdout |
| 30 | +.global print_result |
| 31 | +.type print_result, %function |
| 32 | +.thumb_func |
| 33 | +print_result: |
| 34 | + push {r1-r3, lr} |
| 35 | + |
| 36 | + @ Convert number in r0 to ASCII ('0' + value) |
| 37 | + add r0, r0, #48 @ Convert to ASCII ('0' = 48) |
| 38 | + |
| 39 | + @ Load address of result using PC-relative addressing |
| 40 | + adr r3, result_ptr @ Load address of result into r3 |
| 41 | + ldr r3, [r3] @ Dereference pointer to get real address |
| 42 | + strb r0, [r3, #8] @ Store ASCII digit in result buffer |
| 43 | + |
| 44 | + @ Write "Result: X\n" to stdout |
| 45 | + mov r0, #STDOUT @ fd = 1 (stdout) |
| 46 | + adr r1, result_ptr @ Load result address using literal pool |
| 47 | + ldr r1, [r1] @ Dereference pointer |
| 48 | + mov r2, #10 @ size = 10 |
| 49 | + mov r7, #SYS_WRITE @ syscall: write |
| 50 | + svc #0 |
| 51 | + |
| 52 | + pop {r1-r3, pc} |
| 53 | + |
| 54 | +@ Entry Point (_start) |
| 55 | +.global _start |
| 56 | +.type _start, %function |
| 57 | +.thumb_func |
| 58 | +_start: |
| 59 | + mov r0, #3 @ First argument (a) |
| 60 | + mov r1, #4 @ Second argument (b) |
| 61 | + adr r2, add_ptr @ Load function pointer address |
| 62 | + ldr r2, [r2] @ Dereference pointer |
| 63 | + bl sum @ Call sum(a, b, add) |
| 64 | + |
| 65 | + bl print_result @ Print the result |
| 66 | + |
| 67 | + mov r7, #SYS_EXIT @ syscall: exit |
| 68 | + mov r0, #0 @ exit code 0 |
| 69 | + svc #0 |
| 70 | + |
| 71 | +@ Literal Pool (for PC-relative addressing) |
| 72 | +.ltorg |
| 73 | +.align 4 |
| 74 | +result_ptr: .word result |
| 75 | +add_ptr: .word add |
| 76 | + |
| 77 | +@ Indirect call target |
| 78 | +.type add, %function |
| 79 | +.thumb_func |
| 80 | +add: |
| 81 | + push {lr} |
| 82 | + add r0, r0, r1 @ r0 = r0 + r1 |
| 83 | + pop {pc} |
| 84 | + |
| 85 | +.data |
| 86 | +result: |
| 87 | + .asciz "Result: X\n" |
0 commit comments