diff --git a/rtl/SYSTEM.java b/rtl/SYSTEM.java
index 38f488694a9b8996766edfa36d342f7a00b33a3c..20cbe60f2115f1167d1076d32f81b2f7a3040386 100644 (file)
--- a/rtl/SYSTEM.java
+++ b/rtl/SYSTEM.java
return i;
}
+ public static String STRING(byte[] x)
+ {
+ return new String(x, 0, LEN(x));
+ }
+
public static void COPY(byte[] x, byte[] v)
{
- int len_x = LEN(x);
- int len_v = v.length - 1;
- int len = (len_x < len_v) ? (len_x) : (len_v);
- for(int i = 0; i < len; i++)
+ int ix = LEN(x);
+ int iv = v.length - 1;
+
+ int i = 0;
+ int len = (ix < iv) ? (ix) : (iv);
+ while(i < len)
{
v[i] = x[i];
+ i += 1;
+ }
+ v[i] = 0;
+ }
+
+ public static int STRCMP(byte[] a, byte[] b)
+ {
+ int i = 0;
+ while(a[i] != 0 && a[i] == b[i])
+ {
+ i += 1;
}
- v[len] = 0;
+ return a[i] - b[i];
}
public static void HALT(long n)
{
assert x : n;
}
+
+ public static void TRAP(long n)
+ {
+ if(n == -1)
+ {
+ throw new RuntimeException("CASE TRAP");
+ }
+ else if(n == -2)
+ {
+ throw new RuntimeException("WITH TRAP");
+ }
+ else if(n == -3)
+ {
+ throw new RuntimeException("NOT IMPLEMENTED");
+ }
+ else
+ {
+ throw new RuntimeException("TRAP CODE " + n);
+ }
+ }
+
+ public static int ASH(int x, int n)
+ {
+ return (n > 0) ? (x << n) : (x >> Math.abs(n));
+ }
+
+ public static long ASH(long x, long n)
+ {
+ return (n > 0) ? (x << n) : (x >> Math.abs(n));
+ }
+
+ public static int LSH(int x, int n)
+ {
+ return (n > 0) ? (x << n) : (x >>> Math.abs(n));
+ }
+
+ public static long LSH(long x, long n)
+ {
+ return (n > 0) ? (x << n) : (x >>> Math.abs(n));
+ }
+
+ public static int ROT(int x, int n)
+ {
+ if(n > 0)
+ {
+ return (x << n) | (x >>> (Integer.SIZE - n));
+ }
+ else
+ {
+ n = Math.abs(n);
+ return (x >>> n) | (x << (Integer.SIZE - n));
+ }
+ }
+
+ public static long ROT(long x, long n)
+ {
+ if(n > 0)
+ {
+ return (x << n) | (x >>> (Long.SIZE - n));
+ }
+ else
+ {
+ n = Math.abs(n);
+ return (x >>> n) | (x << (Long.SIZE - n));
+ }
+ }
}