Comment all the things

master prak-2
kolaente 4 years ago
parent 3f46b6acf6
commit 941ea66e58
Signed by: kolaente
GPG Key ID: F40E70337AB24C9B
  1. 74
      hal_test.go

@ -72,39 +72,49 @@ func TestNewton1(t *testing.T) {
input := []string{ input := []string{
"01 START", "01 START",
"02 LOADNUM 1", "02 LOADNUM 1",
"03 STORE 10", "03 STORE 10", // Every x is saved to reg 10
"10 MUL 10",
"11 MUL 10", // f(x)
"12 STORE 12", "10 MUL 10", // x²
"13 MUL 10", "11 MUL 10", // x³
"14 MUL 10", "12 STORE 12", // Saving x³ for later
"15 STORE 11", "13 MUL 10", // x⁴
"21 LOAD 12", "14 MUL 10", // x⁵
"22 MULNUM 5", "15 STORE 11", // Save x⁵ in reg 11
"30 ADD 11", "21 LOAD 12", // Load x³
"31 SUBNUM 5", "22 MULNUM 5", // x³ * 5
"32 STORE 20", "30 ADD 11", // (x³ * 5) + x⁵
"33 SUB 50", "31 SUBNUM 5", // ((x³ * 5) + x⁵) - 5
"34 JUMPNULL 66", "32 STORE 20", // Store the result of f(x) in 20
"35 LOAD 20",
"36 STORE 50", // Exit condition
"40 LOAD 10", "33 SUB 50", // reg 50 contains the last result which we compare with the last one
"41 MUL 10", "34 JUMPNULL 66", // If both are equal, we go to line 66
"42 STORE 21", "35 LOAD 20", // Otherwise save the last result of f(x) as last result
"43 MUL 10", "36 STORE 50", // and continue
"44 MUL 10",
"45 MULNUM 5", // f'(x)
"46 STORE 22", "40 LOAD 10", // Load x
"47 LOAD 21", "41 MUL 10", // x²
"48 MULNUM 15", "42 STORE 21", // Save x² for later
"49 ADD 22", "43 MUL 10", // x³
"50 STORE 30", "44 MUL 10", // x⁴
"60 LOAD 20", "45 MULNUM 5", // x⁴ * 5
"46 STORE 22", // Save 5x⁴ to reg 22
"47 LOAD 21", // load x² from earlier
"48 MULNUM 15", // x² * 15
"49 ADD 22", // 15x² + 5x⁴ from earlier
"50 STORE 30", // Save the result of f'(x) to reg 30
// x - (f(x) / f'(x))
"60 LOAD 20", // f(x) / f'(x)
"61 DIV 30", "61 DIV 30",
"62 STORE 40", "62 STORE 40", // Store the result of it in reg 40
"63 LOAD 10", "63 LOAD 10", // Load the x again
"64 SUB 40", "64 SUB 40", // x - (f(x) / f'(x))
"65 JUMP 03", "65 JUMP 03", // Start at the beginning
// Load the result and print it
"66 LOAD 10", "66 LOAD 10",
"67 OUT 0", "67 OUT 0",
"68 STOP", "68 STOP",

Loading…
Cancel
Save