Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

DZone's Guide to

# Implementing Simple Sort Algorithms in ARM Assembly (Part 1)

### Implementing common sort algorithms on Raspberry Pi in ARM Assembly, starting with Simple Sort.

· IoT Zone
Free Resource

Comment (1)

Save
{{ articles[0].views | formatCount}} Views

Discover why Bluetooth mesh is the next evolution of IoT solutions. Download the mesh overview.

A while back I started to learn some ARM Assembly on the Raspberry Pi (out of curiosity, for no other better reason). I thought it would be interesting to couple this with re-learning some of the basic/standard/common algorithms at the same time, such as common sort algorithms.

So as my first step, since this is turning out to be far more work than I expected (!), here’s my ARM ASM source so far to iterate through a list of 4 byte integer values and print the values to the console using C’s printf. I’ll post further updates as I make progress:

``````.global main
main:
push {ip, lr}
MOV R6, #0 @offset to data
loop:
LDR R5, =nums @ addr of string to R5
LDR R4,[R5,R6] @load current num from R5 with offset R6
MOV R1,R4 @move num for output
BL printf
CMP R6,#16 @ 0 plus 4*4bytes for 5 entries in array
ADD R6,R6, #4 @inc offset by 4 bytes
BNE loop
_exit:
POP {ip, lr}
MOV R1, #0
MOV R7, #1
SWI 0
nums:
.word 5,2,7,1,8
.data
output:
.asciz "%d\n"
``````

I’m sure there’s better ways I can approach this limited code so far, but I’ll come back and revisit this again later. If anyone wants to pull or browse the source so far (and other snippets), it’s on GitHub here: https://github.com/kevinhooke/learning-arm-asm

Take a deep dive into Bluetooth mesh. Read the tech overview and discover new IoT innovations.

Topics:
raspberry pi ,arm ,assembly ,algorithms ,simple sort

Comment (1)

Save
{{ articles[0].views | formatCount}} Views

Published at DZone with permission of Kevin Hooke, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.