问题描述
要将数字乘以2的任意倍数,我将对其进行多次移位.
To multiply a number by any any multiple of 2, I'll shift it those many times.
是否有这种技术可以在更少的周期内将数字乘以10?
Is there any such technique to multiply a number by 10 in less cycles?
推荐答案
80286没有随80386一起推出的桶形移位器.根据Microsoft Macro Assembler 5.0文档(1987)中的时序表, SHL reg,immed8 需要5个n周期,而 SHL reg, 1 需要2个周期. ADD reg,reg 和 MOV reg,reg 一样,需要2个周期. IMUL reg16,immed 需要21个周期.因此,最快的乘以十的方法似乎是:
The 80286 did not have a barrel shifter, that was introduced with the 80386. According to the timing tables in the Microsoft Macro Assembler 5.0 documentation (1987), SHL reg, immed8 takes 5+n cycles, whereas SHL reg, 1 takes 2 cycles. ADD reg, reg takes 2 cycles, as does MOV reg, reg. IMUL reg16, immed takes 21 cycles. Therefore, the fastest way to multiply by ten would appear to be:
; // 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
或者,或者:
; // 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
两种方式都循环十次.
这篇关于80286:乘以10最快的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!