diff options
| author | Yuchen Pei <me@ypei.me> | 2018-01-17 12:01:40 +0100 | 
|---|---|---|
| committer | Yuchen Pei <me@ypei.me> | 2018-01-17 12:01:40 +0100 | 
| commit | fef36fd11c9d3d7f632098c5005bf0e3e5ce5ad9 (patch) | |
| tree | ef7348a6d97b0fb5588dbfebe3b5242f31aab255 /projects/12/MathTest | |
| parent | 3a9265774c48865547702fe58d127c9fe10338a1 (diff) | |
finished Screen.
- a bit slow though
Diffstat (limited to 'projects/12/MathTest')
| -rw-r--r-- | projects/12/MathTest/Math.jack | 12 | ||||
| -rw-r--r-- | projects/12/MathTest/Math.vm | 26 | 
2 files changed, 38 insertions, 0 deletions
diff --git a/projects/12/MathTest/Math.jack b/projects/12/MathTest/Math.jack index 6bac42e..01bce8f 100644 --- a/projects/12/MathTest/Math.jack +++ b/projects/12/MathTest/Math.jack @@ -28,6 +28,18 @@ class Math {          return ~(x & twoToThe[i] = 0);
      }
 +    function int sign(int x) {
 +        if (x > 0) {
 +            return 1;
 +        } else {
 +            if (x < 0) {
 +                return -1;
 +            } else {
 +                return 0;
 +            }
 +        }
 +    }
 +
      /** Returns the absolute value of x. */
      function int abs(int x) {
          if (x > 0){
 diff --git a/projects/12/MathTest/Math.vm b/projects/12/MathTest/Math.vm index dad8ff5..513fc1a 100644 --- a/projects/12/MathTest/Math.vm +++ b/projects/12/MathTest/Math.vm @@ -44,6 +44,32 @@ push constant 0  eq  not  return +function Math.sign 0 +push argument 0 +push constant 0 +gt +if-goto IF_TRUE0 +goto IF_FALSE0 +label IF_TRUE0 +push constant 1 +return +goto IF_END0 +label IF_FALSE0 +push argument 0 +push constant 0 +lt +if-goto IF_TRUE1 +goto IF_FALSE1 +label IF_TRUE1 +push constant 1 +neg +return +goto IF_END1 +label IF_FALSE1 +push constant 0 +return +label IF_END1 +label IF_END0  function Math.abs 0  push argument 0  push constant 0  | 
