80286:乘以 10 最快的方法是什么?

Pro*_*ero 2 assembly micro-optimization x86-16

要将一个数字乘以 2 的任意倍数,我将对其进行多次移位。

有没有这样的技术可以在更少的周期内将数字乘以 10?

nju*_*ffa 5

80286 没有桶形移位器,这是随 80386 一起引入的。根据 Microsoft Macro Assembler 5.0 文档 (1987) 中的时序表,SHL reg, immed8需要 5+n 个周期,而SHL reg, 1需要 2 个周期。ADD reg, reg需要 2 个周期, MOV reg, reg也是如此。IMUL reg16, immed需要 21 个周期。因此,乘以 10 的最快方法似乎是:

           ;       // cycles
shl ax, 1  ; *2    // 2
mov bx, ax ; *2    // 4
shl ax, 1  ; *4    // 6
shl ax, 1  ; *8    // 8
add ax, bx ; *10   // 10
Run Code Online (Sandbox Code Playgroud)

或者,或者:

           ;      // cycles
mov bx, ax ; *1   // 2
shl ax, 1  ; *2   // 4
shl ax, 1  ; *4   // 6
add ax, bx ; *5   // 8
shl ax, 1  ; *10  // 10
Run Code Online (Sandbox Code Playgroud)

无论哪种方式都十个周期。