aaronbloomfield/pdr

lab 8: Suggestion: Use Compiler Explorer for Assembly labs

Closed this issue · 2 comments

http://godbolt.org/ is a website which live-compiles entered C++ to various assembly languages via a selection of compilers. More importantly, it uses color-matched highlighting to show how C++ statements map to assembly lines. Although this could make the assembly labs too easy, I wonder if it could be used to help explain more advanced concepts to the students in the labs.

I just quickly wrote up a program that would need a VMT; it really clearly highlights where the function call is occurring and how you have to navigate to the VMT to figure out which function to call. The VMT itself is also included if you don't filter assembler directives, which is pretty cool.

My code if you want to run this on your own:

class Student {
  public:
  virtual int foo() {
    return 2;
  }
};
class Bar : public Student {
  public:
  virtual int foo() {
    return 5;
  }
};

// Type your code here, or load an example.
int square(int num) {
  	Student* s;
    if (num % 2)
      s = new Student;
  	else
      s = new Bar;
  	
    return s->foo();
}

While we're on the topic tools for the assembly labs: PEDA is a nice extension for GDB that shows what's on the stack in a nice (ASCII) pictorial form. I don't know if we want to install this by default (people might conflate the features of the extension with GDB itself), but it could be a "recommended resource."