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 PA6. To read the details about the various assembly instructions see the documentation about the AVR 8-bit Instruction Set Architecture (AVR Assembly Language).
After viewing the videos, students will be asked to list their top 3 choices for programming partners. We will start from the highest PA1 grade and work our way to the lowest to assign partners. If you do not provide a preference and no one lists you, you will be grouped with someone with a similar grade in PA1.
You can request to not be put into a programming pair. However, then the highest score you can obtain on any programming assignment is a 90%. This reflects the importance that industry and academics place on the ability for Computer Science graduates to be able to work with others.
Your MeggyJava program will be placed in a file called PA6demo.java (the PA6 indicates that the program includes things from the PA6 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. Please email firstname.lastname@example.org the extension you will be using so we can update the preliminary checkin tests to check for your file.
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 examples from ~cs453/public/MJExamples/ 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.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 rae 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 PA6demo.java program make sure to only use Java language features that are in the full MeggyJava grammar. The command
java -jar MJ.jar --checkusage PA6demo.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.
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 PA1 forum on the Canvas discussion board (see course content in Canvas).
The MeggyJava PA6demo.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, which is in the ~cs453/public/MJExamples/ subdirectory.
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 build process page.
In addition, see the PA2bluedot.java, PA2bluedot.java.s, PA5movedot.java, and PA5movedot.java.s files in the ~cs453/public/MJExamples/ subdirectory. 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. 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. Download MJSIM.jar and then 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. (Just wait, we repeat this one more time below).
tar cvf PA1.tar README PA3whiledots.java.s PA6demo.java demo.mov