DEV Community

海前 王
海前 王

Posted on

arm assembled

.text
.global _start

_start:
    ldr r1, =src      // Load address of source string
    ldr r0, =dst      // Load address of destination buffer
    ldr r3, =len      // Load length of string

move:
    cmp r3, #0        // Compare length to 0
    beq end           // If length is 0, branch to end
    ldrb r2, [r1]     // Load byte from source
    strb r2, [r0]     // Store byte to destination
    adds r1, r1, #1   // Increment source address
    adds r0, r0, #1   // Increment destination address
    subs r3, r3, #1   // Decrement length
    b move            // Branch to move

end:
    // Exit system call
    mov r0, #0        // Return code 0
    mov r7, #1        // System call number for exit (1 in ARM)
    swi 0             // Software interrupt to make system call

.data
src:
    .asciz "hello world"  // Source string
len = .-src               // Calculate length of the source string
dst:
    .space 20             // Reserve space for the destination string

Enter fullscreen mode Exit fullscreen mode

Top comments (0)