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

相关推荐
雪碧透心凉_18 小时前
8086汇编(16位汇编)学习笔记00.DEBUG命令使用解析及范例大全
汇编
C66668884 天前
C#多线程
开发语言·汇编·c#
傻童:CPU4 天前
汇编源程序的理解
汇编
木槿714 天前
软件包git没有可安装候选
汇编·git
ok0605 天前
各种开源汇编、反汇编引擎的非专业比较
汇编·开源
roboko_5 天前
MIPS指令集(一)基本操作
汇编
Crossoads5 天前
【汇编语言】内中断(三) —— 中断探险:从do0到特殊响应的奇妙旅程
android·开发语言·javascript·网络·汇编·单片机·机器学习
染指11106 天前
49.第二阶段x86游戏实战2-鼠标点击call深追二叉树
汇编·c++·windows·游戏安全·反游戏外挂·游戏逆向
程序leo源8 天前
深入理解指针
android·c语言·开发语言·汇编·c++·青少年编程·c#
skywalk81639 天前
好玩的汇编编译器NASM:一款基于x86架构的汇编与反汇编软件
汇编