加法运算与乘法运算 [英] Addition operation versus multiplication operation

查看:107
本文介绍了加法运算与乘法运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,加法运算比乘法运算更简单.但是123456 * 3123456 + 123456 + 123456的执行时间会有所不同吗?

I know, that addition operation is more trivial than multiplication operation. But will there be any difference in execution time of 123456 * 3 and 123456 + 123456 + 123456?

乘法到底如何工作?

乘法算法在不同的编程语言中是否有所不同?

Do multiplication algorithms vary in different programming languages?

乘法在低级(即汇编代码)上的外观如何?

How multiplication looks on low-level (i.e. Assembler code)?

推荐答案

在x86汇编语言中,加法和乘法运算如下:

In x86 assembly language the addition and multiplication operations look like this:

ADD [operand1],[operand2] 其中操作数1可以是寄存器,操作数2可以是寄存器,常量或存储器地址 视处理器型号和操作数2类型而定,它需要1到7个时钟

ADD [operand1], [operand2] where operand1 can be register, operand 2 can be register, constant or memory address It takes from 1 to 7 clocks depending on processor model and operand2 type

MUL [操作数];用于无符号乘法 将累加器寄存器(AL,AX,EAX)的内容与操作数相乘,该操作数可以是寄存器或存储器地址.同样,根据操作数和处理器型号的不同,它需要12-38个时钟 还有一个MUL的版本可以进行符号乘法.

MUL [operand] ;for unsigned multiplication multiplies the content of the accumulator register (AL, AX, EAX) with operand, which can be a register or a memory address. And again, depending on the type of the operand and processor model, it takes 12-38 clocks There's also a version of MUL that does signed multiplication.

这是核心汇编语言,没有像SSE这样的现代SIMD扩展.如上所述,实际速度取决于编译器的优化.

This is core assembly language, without modern SIMD extensions like SSE etc. The real speed, as mentioned above, depends on the compiler optimizations.

智能编译器很可能会将您的123456 + 123456 + 123456替换为3 * 123456

A smart compiler will most likely replace your 123456 + 123456 + 123456 with 3*123456

这篇关于加法运算与乘法运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆