2016-08-20 3 views
0

マリーシミュレータの新機能。私はシミュレータを追加する方法を知っていますが、残念ながら私はどのように乗算するのか分かりません。 たとえば、次のコードを入力することができます。S = x * Y + z ありがとうございます。マリーシミュレータでの乗算と加算の方法

答えて

0

繰返し加算を使用して乗算を実装できます。

ここには基本的なアルゴリズムがあります。擬似コードで

For positive integers use the algorithm: 
    Result = Result - Multiplier 
    Multiplicand = Multiplicand - 1 
For negative integers use the algorithm: 
    Result = Result + Multiplier 
    Multiplicand = Multiplicand + 1 

while Multiplicand != 0 
    if Multiplicand > 0 
     Result = Result - Multiplier 
     Multiplicand = Multiplicand - 1 
    else 
     Result = Result + Multiplier 
     Multiplicand = Multiplicand + 1 

これは乗数と被乗数を保持するために2つの変数が必要です。 さらに、JNS(Jump-and-Store命令)とJUMPI(Jump Indirect)の汎用ルーチンに変換することができます。

JNS Multiply 

/Somewhere else 
/Define Multiply as a variable 
/JNS will store the current HEX address 
/in Multiply and start executing the next 
/line 

Multiply, DEC 0 

/*** Multiply Body ***/

/Lastly use JUMPI to Jump Indirectly 
/back to where Multiply was 
/executed from 

JUMPI Multiply