Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 通过重复加法优化此乘法代码,以使循环次数最少_Assembly_Optimization_Multiplication_Marie - Fatal编程技术网

Assembly 通过重复加法优化此乘法代码,以使循环次数最少

Assembly 通过重复加法优化此乘法代码,以使循环次数最少,assembly,optimization,multiplication,marie,Assembly,Optimization,Multiplication,Marie,这个程序使用一个循环,通过使用 重复添加。我需要帮助优化程序,使其尽可能少地循环。例如 程序只会循环3次来计算3*6。即6+6+6 ORG 100 Load Y /load second value to be used as counter Store Ctr /Store as a counter Loop, Load Sum /load to the sum Add X /Add X to sum Store Sum /Store result in Sum Load Ctr Subt O

这个程序使用一个循环,通过使用 重复添加。我需要帮助优化程序,使其尽可能少地循环。例如 程序只会循环3次来计算3*6。即6+6+6

ORG 100
Load Y /load second value to be used as counter
Store Ctr /Store as a counter
Loop, Load Sum /load to the sum
Add X /Add X to sum
Store Sum /Store result in Sum
Load Ctr
Subt One / Decrement counter
Store Ctr /Store counter
SkipCond 400 /if AC=0 , discontinue looping
Jump Loop /if acnot 0 , continue looping
Endloop, Load Sum
Output /Print product
Halt /sum contains the product of x and y
Ctr, Dec 0
X, Dec 0 /initial value of x
Y, Dec 0 /initial value of Y
Sum, Dec 0 /initial value of Sum
One, Dec 1 /the constant value of 1
END

给定3*6示例,此乘法将循环6次或3次,具体取决于参数的顺序。因此,如果确保以较小的参数作为循环计数器,以较大的参数作为加数进入循环,则循环次数将减少

例如,检查一个是否较大,如果需要,在循环之前交换