Logic Tests Series (3) – SUBT


@justyy ‘s series of Logits Tests:

We have implemented the DECR function in last series using the only four keywords in this tiny programming language. This post, you will need to implement the SUBT function which takes two parameters and subtract one from the other i.e. X-=Y

In C++, you can probably implement this using a LOOP.

void subt(unsigned int &x, unsigned int y) {
  for (int i = 0; i < y; i ++) {
     x --;
  }
}

We take one from X variable Y times and the variable X is a reference variable in C++. If we translate this into this language, here it comes:

SUBT(X, Y) {
   LOOP(Y) {
       DECR(X)  // DECR has been implemented, so we can use it.
  }
}

As you see, complex functions are built upon simple instructions namely ASGN, LOOP, INCR and ZERO. We are going to explore more in the next coming series, please be patient!

You may also like: 逻辑测试系列之三 – SUBT

–EOF (The Ultimate Computing & Technology Blog) —

247 words
Last Post: SteemSQL Tutorial: How to Get Historic Posts of Today on SteemIt?
Next Post: SteemSQL Tutorial: What is Your Monthly Income on Steemit?

The Permanent URL is: Logic Tests Series (3) – SUBT (AMP Version)

Leave a Reply