The goal of this programming assignment is to introduce you to the source and target languages for the MeggyJava compiler that you will be writing for PA2 through PA5. To read the details about the various assembly instructions see the documentation about the AVR 8-bit Instruction Set Architecture (AVR Assembly Language).
Your MeggyJava program will be placed in a file called PA5demo.java (the PA5 indicates that the program includes things from the PA5 MeggyJava grammar). See the first recitation off the progress page for instructions on how to write, compile, and upload such programs to the Meggy Jr device. Your demonstration of your program on the Meggy Jr device should be MAX 20 seconds long and be in a demo.mp4 or demo.mov or ... whatever your phone generates that most computers can play.
To compile and run your Meggy Java programs in a Java-only environment for testing, first download the Meggy.java, MeggyException.java, and arg_opts files and place them in a subdirectory called meggy/. Then copy some of the .java examples from the MeggyBuildandRun github repository into the directory that contains the meggy/ subdirectory and run them by typing the following:
javac PA3whiledots.java java PA3whiledotsNOTE that most of the MeggyJava programs contain infinite loops. The run-time library implemented in meggy/Meggy.java reads in an arg_opts file with information about how many Meggy methods to execute before exiting the program. It is also possible to specify what buttons are to be considered down between delay() calls so as to test user input in the Java-only version. For example, the following entries in an arg_opts file:
200 false A delay B Up delaymean that 200 Meggy run-time methods can be called before execution will be stopped even if we have an infinite loop. The false indicates that the delays are not being simulated in Java (we are not actually putting in a delay so that testing goes faster). The A indicates that any time before the first call to the delay method, if there is a query about the A button being pressed the library will return true. For all other buttons false will be returned. The next line with the word "delay" on it will line up with the first call to delay that occurs in the program. After that delay call and before the next delay call, both the B and Up buttons are assumed pressed. This is how we can test MeggyJava programs without depending on the device or a predictable and perfect user.
When writing the MeggyJava PA5demo.java program make sure to only use Java language features that are in the full MeggyJava grammar. The command
java -jar MJ.jar --checkusage PA5demo.javawill show you which abstract syntax tree node types you are missing in your program. That can help you figure out what you left out. The reference compiler MJ.jar will throw a parse error if your program contains something that is not in the MeggyJava subset.
MJ.jar can be found in the MeggyBuildandRun github repository.
The MJ reference compilers generate a bunch of files (Program.java.*). Check them out if you would like, but they are not relevant to this assignment. Also feel free to ask questions on the Piazza discussion board using the pa1 tag.
The MeggyJava PA5demo.java program is converted into assembly by the reference compiler. A LOT OF ASSEMBLY! To start learning about the assembly language, this second part of the assignment has you write the AVR assembly code for a small Meggy Java program, PA3whiledots.java.
For this part of the assignment, you will need to read the Meggy Jr programming guide. The programming guide describes the run-time library interface we are using in this class called MeggyJr Simple. We make some modifications to that interface and you can see the library for this class in the MeggyJrSimple.h and MeggyJrSimple.cpp files provided on the MeggyBuildandRun github repository.
In addition, see the PA2bluedot.java, PA2bluedot.java.s, PA5movedot.java, and PA5movedot.java.s files in the MeggyJavaExampleFiles github repository. These four files show you some Meggy Java input files and what your compiler might generate as .s files. The .s files are well commented to help you understand what is going on. Keep in mind that the PA3whiledots.java.s file you submit CANNOT use push or pop (EXCEPT for the pushes of r29 and r28 in the prologue and their pops in the epilogue. These are needed for MJSIM.jar to work right). You will have to THINK about how AVR assembly works to figure out how to remove those.
The .s files can be simulated using Meggy Simulator MJSIM.jar provided for this class. MJSIM.jar can be found in the MeggyBuildandRun github repository). Run the GUI version by typing:
java -jar MJSIM.jarand then loading a .s file. You can step through the execution of a .s file line by line and see how the stack, heap, and register values change. If you want to run the simulator in batch mode to produce the output we compare with the Java-only library, then type the following:
java -jar MJSIM.jar -b -f PA3whiledots.java.s
The PA3whiledots.java.s file that you write will need to be interpreted by MJSIM.jar and produce the same output as just running the Java-only version for PA3whiledots.java. So that you do not just submit the AVR assembly code generated by the reference compiler, your PA3whiledots.java.s file CANNOT contain any push or pop commands. (EXCEPT for the pushes of r29 and r28 in the prologue and their pops in the epilogue. These are needed for MJSIM.jar to work right.) (Just wait, we repeat this at least one more time below).
tar cvf PA1.tar README PA3whiledots.java.s PA5demo.java demo.mp4
turnin cs453PA1 PA1.tarMake sure to check out much of the MeggyJava grammar your demo covers (see --checkusage above). Testing the correctness of PA3whiledots.java.s is up to you. Your PA3whiledots.java.s file CANNOT contain any push or pop commands. (EXCEPT for the pushes of r29 and r28 in the prologue and their pops in the epilogue. These are needed for MJSIM.jar to work right.)