Skip to content

Instantly share code, notes, and snippets.

@vpetrigo
Last active January 9, 2020 09:20
Show Gist options
  • Save vpetrigo/ec4de9aebffc5c9dfd06871a18ad74a7 to your computer and use it in GitHub Desktop.
Save vpetrigo/ec4de9aebffc5c9dfd06871a18ad74a7 to your computer and use it in GitHub Desktop.
ARM assembler memory copy example
.thumb_func
.align 2
.globl mem_copy
.type mem_copy, %function
mem_copy:
cmp r1, r2
itte ne
ldrne r3, [r0], #4
strne r3, [r1], #4
beq 1f
b mem_copy
1:
bx lr
// Rowley CrossWorks, runtime support.
//
// Copyright (c) 2001-2020 Rowley Associates Limited.
//
// This file may be distributed under the terms of the License Agreement
// provided with this software.
//
// THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.thumb_func
memory_copy:
cmp r0, r1
beq 2f
subs r2, r2, r1
beq 2f
1:
ldrb r3, [r0]
adds r0, r0, #1
strb r3, [r1]
adds r1, r1, #1
subs r2, r2, #1
bne 1b
2:
bx lr
.thumb_func
memory_set:
cmp r0, r1
beq 1f
strb r2, [r0]
adds r0, r0, #1
b memory_set
1:
bx lr
.thumb_func
memory_copy:
cmp r1, r2
itte ne
ldrne r3, [r0], #4
strne r3, [r1], #4
beq 1f
b memory_copy
1:
bx lr
// TODO: Something strange happens with CrossWorks build and memory_set
// function as it works with POR event only when BSS is zeroed on per byte basis
.thumb_func
memory_set:
cmp r0, r1
itt lt
strlt r2, [r0], #4
blt memory_set
1:
bx lr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment