ARM-8 x/1 哪去了

403be8: 52800020 mov w0, #0x1 // #1

403bec: 52800001 mov w1, #0x0 // #0

403bf0: 7100077f cmp w27, #0x1 // w27=rep

403bf4: 54000aac b.gt 403d48 <ferror@plt+0x1e68>

if (rep > 1) {

// b.gt 403d48

}

/*403d48: 2a0003f7 mov w23, w0 // div=w23=w0=1

403d4c: 0b000800 add w0, w0, w0, lsl #2 // w0=1+1<<2=1+4=5, 乘法第一步,加法

403d50: 2a0103f9 mov w25, w1 // w25=w1=0
403d54: 11000421 add w1, w1, #0x1 // digits=w1=0+1=1

403d58: 531f7800 lsl w0, w0, #1 // w0=5<<1=10, div *= 10, 乘法第二步,左位移

403d5c: 1ac00f62 sdiv w2, w27, w0 // w2=w27/w0=rep/div

403d60: 35ffff42 cbnz w2, 403d48 <ferror@plt+0x1e68>

digits = 0;

for (div = 1; x / div; div *= 10) // 调试时跟踪指令解开了x/1之谜。digits先加1,即简化了x/1这一步。

digits++; // 对于这步的优化条件,依据为进来前的cmp指令比较大于1。

也可写成:

digits = 1;

for (div = 10; x / div; div *= 10)

digits++

调试:

Breakpoint 1, 0x0000000000403d48 in ?? ()
=> 0x0000000000403d48: f7 03 00 2a mov w23, w0

(gdb) watch $w0

Watchpoint 2: $w0

(gdb) n

0x0000000000403d4c in ?? ()
=> 0x0000000000403d4c: 00 08 00 0b add w0, w0, w0, lsl #2

(gdb) watch $w23

Watchpoint 3: $w23

(gdb) n

Watchpoint 2: $w0

Old value = 1

New value = 5

0x0000000000403d50 in ?? ()
=> 0x0000000000403d50: f9 03 01 2a mov w25, w1

(gdb)

0x0000000000403d54 in ?? ()
=> 0x0000000000403d54: 21 04 00 11 add w1, w1, #0x1

(gdb)

0x0000000000403d58 in ?? ()
=> 0x0000000000403d58: 00 78 1f 53 lsl w0, w0, #1

(gdb)

Watchpoint 2: $w0

Old value = 5

New value = 10

0x0000000000403d5c in ?? ()
=> 0x0000000000403d5c: 62 0f c0 1a sdiv w2, w27, w0

(gdb)

0x0000000000403d60 in ?? ()
=> 0x0000000000403d60: 42 ff ff 35 cbnz w2, 0x403d48

(gdb)

Breakpoint 1, 0x0000000000403d48 in ?? ()
=> 0x0000000000403d48: f7 03 00 2a mov w23, w0

(gdb)

Watchpoint 3: $w23

Old value = 1

New value = 10

0x0000000000403d4c in ?? ()
=> 0x0000000000403d4c: 00 08 00 0b add w0, w0, w0, lsl #2

(gdb)

Watchpoint 2: $w0

Old value = 10

New value = 50

0x0000000000403d50 in ?? ()
=> 0x0000000000403d50: f9 03 01 2a mov w25, w1

(gdb)

0x0000000000403d54 in ?? ()
=> 0x0000000000403d54: 21 04 00 11 add w1, w1, #0x1

(gdb)

0x0000000000403d58 in ?? ()
=> 0x0000000000403d58: 00 78 1f 53 lsl w0, w0, #1

(gdb)

Watchpoint 2: $w0

Old value = 50

New value = 100

0x0000000000403d5c in ?? ()
=> 0x0000000000403d5c: 62 0f c0 1a sdiv w2, w27, w0

相关推荐
safe03020 小时前
SPA和SSR
开发语言·前端·javascript·汇编·vue.js·react.js·前端框架
不会编程的小江江2 天前
【ARM】(三)ARM指令集与汇编基础
汇编·arm开发
FreeBuf_4 天前
HexForge:一款用于扩展安全汇编和十六进制视图的IDA插件
汇编·安全
xiaozhiwise7 天前
ARM SIMD instruction -- fcvtzs
汇编
代码欢乐豆7 天前
Linux期末考试编程题汇编
linux·汇编·chrome
bcdaren8 天前
《Windows PE》7.4 资源表应用
c语言·汇编·windows·pe
Fasthand_9 天前
C语言内联汇编
c语言·开发语言·汇编
charlie11451419110 天前
基于x86_64汇编语言简单教程6: 变量,常量,与运算
汇编·学习·教程·asm
jiao0000111 天前
微机原理与接口技术—— 8086 CPU 指令系统总结(2)
汇编