CS 453 Programming Assignment #1 — MeggyJava and AVR warmup

Introduction

In this assignment you will be writing a creative MeggyJava program that you will demonstrate on the Meggy Jr device. You can video your short, 15 second demonstration with your phone or you can schedule an appointment with me Monday February 2nd and demonstrate your program to my phone to create a video. The MeggyJava program should use the full MeggyJava grammar. You will also be writing an AVR program to match the behavior of a small Meggy Java program.

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).

Programming Partners in CS453

PA1 is an individual programming assignment. PA2 through PA6 will be done in teams of two. The other students will be able to view your demonstration. In your demonstration, you CAN mention the times of the day and which days you can most easily work with a partner and describe your approach to partner work. However your demonstration (1) CANNOT show any part of your body or face other than your hands, (2) CANNOT include a description of grades you have received in other courses, or (3) CANNOT include a description of your current paid work experience. The videos will be prescreened before they are posted for the class to view. If your video does not fit the above requirements, then your video will not be posted and you will not get credit for the video.

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.

The Assignment

MeggyJava program

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 mstrout@cs.colostate.edu 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 PA3whiledots
NOTE 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
delay
mean 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.java
will 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).

AVR version of MeggyJava program

The MeggyJava compiler you write in CS453 will generate Atmel assembly language. Specifically you will be generating the subset of instructions that are compatible with the MeggySim simulator.

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.jar
and 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).

Submitting the Assignment

Grading

Late Policy

Late assignments will be accepted up to 48 hours past the due date for a 10% deduction. The assignment will not be accepted past this period. Late means anything after 11:59pm on the day the assignment is due, including 12 midnight.


mstrout@cs.colostate.edu, 1/23/13
Wim Bohm, 2014.
mstrout@cs.colostate.edu, 1/22/15