Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hello World in ARM Assembly without data section

I have a "Hello, World!" program in ARM assembly language and I want to convert it into shell code to execute it in a memory region. In Intel Assembly language I got rid of the .data section since only the .text section is being used when converting to shell code. (See here)

Now I am struggling to do the same in ARMs assembly language. The basis is the following code:

ARM Assembly Hello World

.global _start

_start:
    mov r7, #4
    mov r0, #1
    ldr r1,=string
    mov r2, #12
    swi 0
    mov r7, #1
    swi 0

.data
string:
  .ascii "Hello, World"

Modified ARM Assembly Hello World to omit the .data section

.global _start
.global mymessage

mymessage:
    mov r7, #4
    mov r0, #1
    pop {r1}
    mov r2, #12
    swi 0
    mov r7, #1
    swi 0

_start:
    bl mymessage
    .ascii "Hello, World"

But this doesn't work, since this is an "illegal instruction" apparently. Any ideas?

like image 447
Marvin Avatar asked Oct 18 '25 19:10

Marvin


1 Answers

ARM already has PC-relative addressing, and in any case, bl does not push the return address on the stack.

This works:

.global _start

_start:
    mov r7, #4
    mov r0, #1
    adr r1, string
    mov r2, #12
    swi 0
    mov r7, #1
    swi 0

string:
  .ascii "Hello, World"
like image 195
Jester Avatar answered Oct 21 '25 08:10

Jester