汇编求最大公约数:
.text
.global _start @声明一个全局函数_start入口
_start: @函数入口地址 _start
mov r0, #0x9
mov r1, #0x12
my_func1:
cmp r0,r1
beq stop
subcc r1,r1,r0
subhi r0,r0,r1
b my_func1
stop: @ 标签stop
b stop @ 跳转到stop标签下,第一条指令执行,相当于 while(1)
.end
用汇编实现for循环,实现0~100相加:
.text
.global _start @声明一个全局函数_start入口
_start: @函数入口地址 _start
mov r0, #0
mov r1, #0x64
mov r3, #0
bl my_func
my_func:
cmp r0,r1
add r3 , r3,r0
add r0 , r0 ,#1
moveq pc,lr
bl my_func
stop: @ 标签stop
b stop @ 跳转到stop标签下,第一条指令执行,相当于 while(1)
.end
结果如下: