Project 12> two digits numerics

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Project 12> two digits numerics

kraftwerk1611
Hi,

when two or more digits numbers is assigned to a variable of 'int' type, VM emulator is not printing them out.

var int x;
let x=13;
do Output.printInt(x);

The above code prints '=' on VM emulator screen. If x=37 then I see 'U' printed on screen. With single digit integers everything is fine.

What could be causing this behavior?

Also printing strings like "Result is ",  using printString(),  is printed on screen with some characters missing

thanks.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Project 12> two digits numerics

cadet1620
Administrator
I'm assuming that this is running with your OS code.

Printing '=' instead of 13 looks like a conversion problem in printInt().  The ASCII code for '=' is 61, the code for '0' = 48.  61-48 = 13.

The missing characters in printString() are all in the odd-numbered columns.  Check you code for drawing characters into the high half-words.

This seems like a strange interaction, assuming that String and Output both pass their individual tests.  Some problem with Math.multiply() or divide() ?

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Project 12> two digits numerics

kraftwerk1611
When used with given OS math.vm, everything is good.

I was trying to build Math class function by function implementing first the two functions min() and max() and testing these with following code in main.jack. May be this is not the right way to test partially implemented code.

class Main {
   function void main() {
      var int x,y,z,result;
          let x=13;
          let y=7;
          let z=-5;
           
         
          let result=Math.max(x,y);
          do Output.printInt(x);
          do Output.println();      // New line
          do Output.printInt(y);
          do Output.println();      // New line
          do Output.printString("Result is:!");
          do Output.println();      // New line
          do Output.printInt(result);
          do Output.println();      // New line
           do Output.printInt(z);
      return;
         
   }
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Project 12> two digits numerics

cadet1620
Administrator
The Math class must be functional for Screen and Output to work.

You need to develop and test your Math.jack in the projects/12/MathTest directory.  There is a supplied MathTest.tst file that you need to run in the VMEmulator to test your Math.jack.

Compile the MathTest directory. There should be only 2 VM files: Main.vm and Math.vm.

MathTest.jack executes all the functions in Math.jack independently, putting the result of each call into individual memory addresses so that you can see the results call by call.

If you want to start by implementing min and max, you will need to add appropriate 'return' and 'return 0' commands to the other function stubs so that the code will compile.

It can be hard to see the compare results in the VM Emulator.  If so, look at the MathTest.cmp and MathTest.out files in a text editor.

Learn how to use the Breakpoints in the VM Emulator.  For instance, set a name=currentFunction, value=Math.max breakpoint and you will be able to step through your Math.max() function.

-Mark
Loading...