Data Organization on the Memory

  1. Convert the following C functions to assembly code.

    int swap_int(int *a, int *b){
        int aux = *a;
        *a = *b;
        *b = aux;
        return 0;
    };
    
    int swap_short(short *a, short *b){
        short aux = *a;
        *a = *b;
        *b = aux;
        return 0;
    };
    
    int swap_char(char *a, char *b){
        char aux = *a;
        *a = *b;
        *b = aux;
        return 0;
    };
    

    Assistant Link

  2. Convert the following C functions to assembly code.

    int middle_value_int(int *array, int n){
        int middle = n / 2;
        return array[middle];
    };
    
    short middle_value_short(short *array, int n){
        int middle = n / 2;
        return array[middle];
    };
    
    char middle_value_char(char *array, int n){
        int middle = n / 2;
        return array[middle];
    };
    
    int value_matrix(int matrix[12][42], int r, int c){
        return matrix[r][c];
    };
    

    Assistant Link

  3. Convert the following C functions to assembly code, using the program stack to store local variables.

    int fill_array_int(){
        int array[100];
        for (int i = 0; i < 100; i++)
            array[i] = i;
        return mystery_function_int(array);
    };
    
    int fill_array_short(){
        short array[100];
        for (short i = 0; i < 100; i++)
            array[i] = i;
        return mystery_function_short(array);
    };
    
    int fill_array_char(){
        char array[100];
        for (char i = 0; i < 100; i++)
            array[i] = i;
        return mystery_function_char(array);
    };
    

    Assistant Link

For exercises 4 and 5, the following struct must be used

typedef struct Node {
  int a;
  char b, c;
  short d;
} Node;
  1. Convert the following C function to assembly code.

    int node_op(Node *node){
        return node->a + node->b - node->c + node->d;
    };
    

    Assistant Link

  2. Convert the following C function to assembly code, using the program stack to store local variables.

    int node_creation(){
        Node node;
        node.a = 30;
        node.b = 25;
        node.c = 64;
        node.d = -12;
        return mystery_function(&node);
    };
    

    Assistant Link