ABI Compliance

  1. Write a program with a global variable named my_var of type int (32 bits), initialized with the value 10 and a function named increment_my_var that increments 1 to this global variable.

    Assistant Link

  2. Write a program that uses only caller-save registers and the sp and ra registers, it must have a function called 'my_function' that receives three values and does the following:

    • Computes the sum of the first two values

    • Calls a function called 'mystery_function' passing the sum and the first value as parameters in this order

    • Computes the difference between the second value and the returned value of the 'mystery_function'

    • Sums the third value to the difference

    • Calls 'mystery_function' again passing the sum and the first value as parameters in this order

    • The C code below exemplifies these steps

      int my_function(int a, int b, int c){
      int aux = b - mystery_function(a+b, a) + c;
      return c - mystery_function(aux, b) + aux;
      };
      

    Assistant Link

  3. Convert the following C function to assembly code. Note: char and short values are extended to 32 bits when stored in the program stack.

    int operation(){
        int a = 1;
        int b = -2;
        short c = 3;
        short d = -4;
        char e = 5;
        char f = -6;
        int g = 7;
        int h = -8;
        char i = 9;
        char j = -10;
        short k = 11;
        short l = -12;
        int m = 13;
        int n = -14;
        return mystery_function(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
    }
    

    Assistant Link

  4. Convert the following C function to assembly code. Note: char and short values are extended to 32 bits when stored in the program stack.

    int operation(int a, int b, short c, short d, char e, char f, int g, int h, char i, char j, short k, short l, int m, int n){
        return b + c - f + h + k - m;
    };
    

    Assistant Link

  5. Convert the following C function to assembly code.

    int operation(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n){
        return mystery_function(n, m, l, k, j, i, h, g, f, e, d, c, b, a);
    };
    

    Assistant Link