onilink_

fibo vmasm

May 24th, 2020
1,993
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1.     // fibonacci algorithm
  2.     {
  3.         Script s;
  4.        
  5.         uint32_t label_for = s.createLabel();
  6.         uint32_t label_end = s.createLabel();
  7.        
  8.         // a = 1
  9.         s.pushi_e(1);
  10.         s.pop_v(var_a, DataType::i32);
  11.        
  12.         // b = 1
  13.         s.pushi_e(1);
  14.         s.pop_v(var_b, DataType::i32);
  15.        
  16.         // for(i=0; i<10; i+=1) {
  17.         s.pushi_e(0);
  18.         s.pop_v(var_i, DataType::i32);
  19.         s.setLabel(label_for);
  20.         s.push_v(var_i);
  21.         s.pushi_e(10);
  22.         s.set(DataType::i32, DataType::variable, CompFunc::lt);
  23.         s.bf(label_end);
  24.        
  25.         // t = b
  26.         s.push_v(var_b);
  27.         s.pop_v(var_t, DataType::variable);
  28.        
  29.         // b += a
  30.         s.push_v(var_b);
  31.         s.push_v(var_a);
  32.         s.add(DataType::variable, DataType::variable);
  33.         s.pop_v(var_b, DataType::variable);
  34.        
  35.         // a = t
  36.         s.push_v(var_t);
  37.         s.pop_v(var_a, DataType::variable);
  38.        
  39.         // i+=1
  40.         s.push_v(var_i);
  41.         s.pushi_e(1);
  42.         s.add(DataType::i32, DataType::variable);
  43.         s.pop_v(var_i, DataType::variable);
  44.         s.b(label_for);
  45.         s.setLabel(label_end);
  46.        
  47.         script_event = sim.addObjectEvent(
  48.                     object0_ind, EventType::create, std::move(s) );
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment