View Javadoc

1   package com.tapina.robe.swi.clib.string;
2   
3   import com.tapina.robe.runtime.ByteArray;
4   import com.tapina.robe.runtime.Environment;
5   import com.tapina.robe.runtime.MemoryMap;
6   import com.tapina.robe.swi.clib.Stub;
7   
8   /***
9    * This function compares the first a3 characters of each object and returns a value accordingly.
10   * Returns: Greater than, less than or equal to zero, depending if the object pointed to by a1 is greater than,
11   * less than or equal to the object pointed to by a2.
12   */
13  public class MemCmp extends Stub {
14      public void executeStub(Environment environment) {
15          final MemoryMap memoryMap = environment.getMemoryMap();
16          final int[] R = environment.getCpu().R;
17          final ByteArray obj1 = memoryMap.getByteArray(R[0], R[2], false);
18          final ByteArray obj2 = memoryMap.getByteArray(R[1], R[2], false);
19          for (int i = 0; i < R[2]; i++) {
20              final int b1 = obj1.getByte(i);
21              final int b2 = obj2.getByte(i);
22              if (b1 < b2) {
23                  R[0] = -1;
24                  return;
25              } else if (b1 > b2) {
26                  R[0] = 1;
27                  return;
28              }
29          }
30          R[0] = 0;
31      }
32  }