Links to resources for Bare Metal programming go here.
Please do not post comments/discussions here, just links to info.
Post "contaminating" the sticky will be deleted.
For these use the normal threads.
Code: Select all
.text
.balign 4
.type udiv, %function
.thumb_func
udiv:
# r0 the enumerator
# r1 the denominator
@ at return:
# r2 the whole part
# r3 the remainder
@ assumptions
# the denominator is not 0
# the function does not destroy its arguments or any register above r6
# init
movs r2,#0
movs r3,r0
# determine no. of leading bits in the denominator
clz r6,r1
10: # trap 'division done'
cmp r3,r1
it lo
bxlo lr
# determine preliminary shift size
clz r5,r3
subs r4,r6,r5
# determine preliminary shifted denominator
lsls r5,r1,r4
# adjust shift size and shifted denominator if the shifted denominator outranges the remainder
cmp r3,r5
itt lo
sublo r4,#1
lsrlo r5,#1
# adjust results
subs r3,r5
movs r5,#1
lsls r5,r4
orrs r2,r5
b 10b