mov r2, 0x5000
movt r2, 0x1100
mov r1, #'A'
1:
str r1, [r2]
b 1b
有时在调试时,需要讲寄存器值打印出来,但是在汇编中,不能直接调用打印函数。只能利用汇编直接往串口输出。特记录如下:
mov r9, r2
ldr r8, =0x02020040 //串口地址
mov r7, #'\n'
str r7, [r8]
// 0-3
and r9, r9, #15
// ascii 转换
ADD r9, r9, #48
CMP r9, #58 ; did that exceed ASCII '9'?
ADDHS r9, r9, #7 ; add 'A' - ('0'+10) if needed
str r9, [r8]
// 4-7
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #4
and r9, r9, #15
str r9, [r8]
// 8-11
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #8
and r9, r9, #15
str r9, [r8]
// 12-16
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #12
and r9, r9, #15
str r9, [r8]
// 17-20
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #16
and r9, r9, #15
str r9, [r8]
// 21-24
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #20
and r9, r9, #15
str r9, [r8]
// 25-28
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #24
and r9, r9, #15
str r9, [r8]
//29-32bit
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #28
and r9, r9, #15
str r9, [r8]
mov r7, #'\n'
str r7, [r8]
mov r7, #'\n'
str r7, [r8]
mov r7, #'\n'
str r7, [r8]
mov r9, r3
ldr r8, =0x02020040
mov r7, #'\n'
str r7, [r8]
// 0-3
and r9, r9, #15
str r9, [r8]
// 4-7
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #4
and r9, r9, #15
str r9, [r8]
// 8-11
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #8
and r9, r9, #15
str r9, [r8]
// 12-16
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #12
and r9, r9, #15
str r9, [r8]
// 17-20
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #16
and r9, r9, #15
str r9, [r8]
// 21-24
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #20
and r9, r9, #15
str r9, [r8]
// 25-28
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #24
and r9, r9, #15
str r9, [r8]
//29-32bit
mov r7, #'\n'
str r7, [r8]
mov r9, r2
ror r9, #28
and r9, r9, #15
str r9, [r8]