-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathasm.py
36 lines (29 loc) · 937 Bytes
/
asm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Examples of the workround for unimplemented assembler instructions
# Author: Peter Hinch
# 15th Feb 2015
# Note: these instructions are now supported. I've left this file in place
# to illustrate the technique.
# Source: ARM v7-M Architecture Reference Manual
# Make r8-r11 safe to use by pushing them on the stack
@micropython.asm_thumb
def foo(r0):
data(2, 0xe92d, 0x0f00) # push r8,r9,r10,r11
mov(r8, r0) # Would otherwise crash the board!
data(2, 0xe8bd, 0x0f00) # pop r8,r9,r10,r11
# The signed divide instruction
@micropython.asm_thumb
def div(r0, r1):
data(2, 0xfb90, 0xf0f1)
# Bit reversal
@micropython.asm_thumb
def rbit(r0):
data(2, 0xfa90, 0xf0a0)
# Count leading zeros
@micropython.asm_thumb
def clz(r0):
data(2, 0xfab0, 0xf080)
# Count trailing zeros
@micropython.asm_thumb
def clz(r0):
data(2, 0xfa90, 0xf0a0) # Bit reverse
data(2, 0xfab0, 0xf080) # count leading zeros