看一个函数库C语言出来的IO设置,真不知一般的繁琐,就为了体现计算能力么。。
@ IO口设置,入口SP指向的地址底16位是具体要设置哪一位,
@ SP高16位决定IO的状态,通过繁琐 的计算获得设置的模式
@
sub_80039EC: @ CODE XREF: sub_8000276+20p
@ sub_800029C+20p
PUSH.W {R4-R8,LR}
MOV R2, R0 @ r2=0x40010c00 PB
MOVS R5, #0 @ R5=0
MOVS R6, #0 @ R6=0
MOVS R0, #0 @ R0=0
MOVS R3, #0 @ R3=0
MOVS R4, #0 @ R4=0
MOVS R7, #0 @ R7=0
LDRB.W R12, [R1,#3] @ R12=0X48,利用堆栈传递的数据
AND.W R5, R12, #0xF @ 0X48 & 0XF = 0X8
LDRB.W R12, [R1,#3] @ r12=0x48
TST.W R12, #0x10 @ 检测第4位等不等于1
BEQ loc_8003A18 @ 等于0跳转
LDRB.W R12, [R1,#2] @ R12=0X03 堆栈传递的数据
ORR.W R5, R12, R5 @ 0x03 逻辑或 0x08 = 0x0B
loc_8003A18: @ CODE XREF: sub_80039EC+22j
LDRH.W R12, [R1] @ r12= 0x4000 堆栈传递的数据
TST.W R12, #0xFF @ 测试底8等不等于0XFF
BEQ loc_8003A86 @ 等于0跳转
LDR R4, [R2] @ 取出PB口底8位的设置
MOVS R0, #0 @ R0=0
B loc_8003A80
@ ---------------------------------------------------------------------------
loc_8003A28: @ CODE XREF: sub_80039EC+96j
MOV.W R12, #1 @ r12= 1
LSL.W R3, R12, R0 @ R12左移R0位
LDRH.W R12, [R1] @ R12=0X4000
AND.W R6, R12, R3 @ 0X4000与R3
CMP R6, R3 @ R6和R3比较
BNE loc_8003A7E @ 不等于跳转
LSLS R3, R0, #2 @ R3=R0左移2位
MOV.W R12, #0xF @ R12=0X0F
LSL.W R7, R12, R3 @ 0XF左移R3位
BICS R4, R7 @ 位请0
LSL.W R12, R5, R3 @ R5左移R3
ORR.W R4, R12, R4 @ R12逻辑或R4 = PB1= 0XB
LDRB.W R12, [R1,#3] @ R12= 0X48
CMP.W R12, #0x28 @ R12和0X28比较
BNE loc_8003A68 @ 不等于跳转
MOV.W R12, #1 @ R12 = 1
LSL.W R12, R12, R0
STR.W R12, [R2,#0x14] @ BRR关IO口
B loc_8003A7E
@ ---------------------------------------------------------------------------
loc_8003A68: @ CODE XREF: sub_80039EC+6Cj
LDRB.W R12, [R1,#3] @ 取出条件,堆栈传递的数据
CMP.W R12, #0x48 @ R12和0X48比较
BNE loc_8003A7E @ 不等于跳转
MOV.W R12, #1 @ R12= 1
LSL.W R12, R12, R0 @ 1左移0位
STR.W R12, [R2,#0x10] @ BSRR开IO
loc_8003A7E: @ CODE XREF: sub_80039EC+4Ej
@ sub_80039EC+7Aj ...
ADDS R0, R0, #1
loc_8003A80: @ CODE XREF: sub_80039EC+3Aj
CMP R0, #8 @ 0和8比较
BCC loc_8003A28 @ 如果小于跳转
STR R4, [R2] @ 8位完成把设置的数据写入入口地址
loc_8003A86: @ CODE XREF: sub_80039EC+34j
LDRH.W R12, [R1]
CMP.W R12, #0xFF
BLE locret_8003AFA @ 小于等于0XFF跳转
LDR R4, [R2,#4] @ 读出高8位设置
MOVS R0, #0
B loc_8003AF4
@ ---------------------------------------------------------------------------
loc_8003A96: @ CODE XREF: sub_80039EC+10Aj
ADD.W R12, R0, #8 @ R12=8
MOV.W R8, #1 @ R8= 1
LSL.W R3, R8, R12 @ R8左移R12
LDRH.W R12, [R1] @ 读出存在堆栈里的变量
AND.W R6, R12, R3 @ R12 & r3
CMP R6, R3 @ R6和R3比较
BNE loc_8003AF2 @ 不等于跳转
LSLS R3, R0, #2 @ R0 左移2位
MOV.W R12, #0xF @ R12= 0XF
LSL.W R7, R12, R3 @ R12左移R3位
BICS R4, R7 @ 清0相应位
LSL.W R12, R5, R3 @ R5左移R3
ORR.W R4, R12, R4 @ R12或R4
LDRB.W R12, [R1,#3] @ 读出堆栈传递的数据
CMP.W R12, #0x28 @ R12和0X28比较
BNE loc_8003AD8 @ 不等于跳转
ADD.W R12, R0, #8 @ R8加8 表示高8位
LSL.W R8, R8, R12 @ R8左移R12
STR.W R8, [R2,#0x14] @ 写入关闭IO
loc_8003AD8: @ CODE XREF: sub_80039EC+DEj
LDRB.W R12, [R1,#3] @ 取出堆栈传递的条件数据
CMP.W R12, #0x48 @ 然后用这个数据和0X48比较
BNE loc_8003AF2 @ 没到最高位继续计算
ADD.W R12, R0, #8 @ 表示高8位
MOV.W R8, #1 @ r8= 1
LSL.W R8, R8, R12 @ 左移R12位
STR.W R8, [R2,#0x10] @ 打开IO
loc_8003AF2: @ CODE XREF: sub_80039EC+C0j
@ sub_80039EC+F4j
ADDS R0, R0, #1
loc_8003AF4: @ CODE XREF: sub_80039EC+A8j
CMP R0, #8
BCC loc_8003A96 @ 再算出高8位设置
STR R4, [R2,#4] @ 写入高8位设置
locret_8003AFA: @ CODE XREF: sub_80039EC+A2j
POP.W {R4-R8,PC} @ 返回