Date: 2018-7-15
1、参考:
https://stackoverflow.com/questions/2370942/arm-assembly-print-register-value-in-decimal
2、arm寄存器打印
由于arm寄存器打印都是以十六进制显示的,看起来比较费劲。
因此,最近一直在探索相对比较好用的arm寄存器打印方法,现在有以下两种方法可供参考。
方法一:
print_decimal:
stmfd sp!, {r4,r5,lr}
cmp r0, #0
moveq r0, #'0'
bleq putchar
beq done
mov r4, sp
mov r5, sp
sub sp, sp, #12
rsblt r0, r0, #0 ; r0 = abs(r0)
movlt lr, #1 ; lr = negative ? 1 : 0
movgt lr, #0
ldr r1, =0x1999999a ; r1 = 2^32 / 10
loop: umull r2, r3, r0, r1 ; r3 = r0 / 10
sub r2, r0, r3, lsl #3
sub r2, r2, r3, lsl #1 ; r2 = r0 - 10*r3 = r0 % 10
add r2, r2, #'0'
strb r2, [r4, #-1]!
movs r0, r3
bne loop
cmp lr, #0
movne r0, #'-'
blne putchar
write: ldrb r0, [r4], #1
bl putchar
cmp r4, r5
blt write
add sp, sp, #12
done:
ldmfd sp!, {r4,r5,lr}
mov r0, #'
'
b putchar
方法二:
.macro print_dx in1=d0
mov.u16 r0, in1()[0]
mov.u16 r1, in1()[1]
mov.u16 r1, in1()[2]
mov.u16 r3, in1()[3]
bl printf
.endm
void printf(int r0, int r1, int r2, int r3)
{
printf(Hex: %x, %x, %x, %x
, r0,r1,r2,r3);
printf(Dec: %d, %d, %d, %d
, r0,r1,r2,r3);
return;
}
方法三:
未完待续