ကဲဒါဆို၊ ခုကၽြန္ေတာ္တို႕ရဲ႕ Newton ရဲ႕ displacement equation ကို ကိုယ္ပိုင္ language သုံးၿပီးတြက္ၾကည့္ရေအာင္၊ Code:
void main() { Program MyProgram;
// initialize data first
// "time" variable. Address: 0x0000, value: 200
MyProgram.Add(Instruction(OP_PUT_MEM, 0x0000, 200));
// "acceleration" variable. Address: 0x0004, value: 2
MyProgram.Add(Instruction(OP_PUT_MEM, 0x0004, 2));
// "initial velocity" variable. Address: 0x0008, value: 35
MyProgram.Add(Instruction(OP_PUT_MEM, 0x0008, 35));
// calculate time * time
MyProgram.Add(Instruction(OP_PUSH_STACK, 0, 0));
MyProgram.Add(Instruction(OP_PUSH_STACK, 0, 0));
MyProgram.Add(Instruction(OP_MULTIPLY, 0, 0));
// calculate (acceleration * time2) / 2
MyProgram.Add(Instruction(OP_PUSH_STACK, 0x0004, 0));
MyProgram.Add(Instruction(OP_MULTIPLY, 0, 0));
MyProgram.Add(Instruction(OP_PUT_STACK, 2, 0));
MyProgram.Add(Instruction(OP_DIVIDE, 0, 0));
// calculate (initial velocity * time)
MyProgram.Add(Instruction(OP_PUSH_STACK, 0x0008, 0));
MyProgram.Add(Instruction(OP_PUSH_STACK, 0x0000, 0));
MyProgram.Add(Instruction(OP_MULTIPLY, 0, 0));
// calculate (initial velocity * time) + (acceleration * time2) / 2
MyProgram.Add(Instruction(OP_ADD, 0, 0));
// save to "displacement" variable. Address: 0x000C
MyProgram.Add(Instruction(OP_POP_STACK, 0x000C, 0));
// print the displacement value on screen
MyProgram.Add(Instruction(OP_PUSH_STACK, 0x000C, 0));
MyProgram.Add(Instruction(OP_NUM, 0, 0));
MyProgram.Add(Instruction(OP_END, 0, 0));
vm.Run(MyProgram);
};
ကဲ ဒီေလာက္ဆို ကၽြန္ေတာ္တို႕ language ေလးက ဒီလိုခက္ခက္ခဲခဲ equation
ေတြတြက္လို႕ရၿပီဆိုတာ ေတြ႕ႏိုင္ပါတယ္။ ေသခ်ာတာက သာမန္ calculator
အဆင့္ထက္ေတာ့ အမ်ားႀကီး သာေနပါၿပီ။ Memory ေတြ၊ Stack ေတြကို အရင္
chapters ေတြတုန္းက အပင္ပန္းခံၿပီးေရးထားတဲ့ အက်ိဳးေက်းဇူးပါဘဲ Wink အေပၚက
script ေတြေရးၿပီးရင္ run ၾကည့္ဖို႕လဲ မေမ့ပါနဲ႔။ တျခား equation ေတြလဲ
ထည့္တြက္ၾကည့္လို႕ရေနပါၿပီ။ စမ္းၾကည့္ဖို႕ တိုက္တြန္းလုိက္ပါတယ္။