Lab 03: The Mechanical Arm Controller

In this laboratory, you will explore the programming structures responsible for control the flow of an application. For this, you will implement a hypothetical controller of a mechanical arm. This controller stores the arm program on a array in the memory of the system. This program can have the following commands:

Your program must firstly print on the screen the actual program that the controller will execute. Then you must simulate the execution of the program printing on the screen the actions that the controller are taking. Above is the pseudo code for the program:

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.

int main(void) {

unsigned int * program = 0x10010000;

for(int i = 0; program[i] != STOP; i++){
    print_cmd(program[i]);
}

unsigned int PC = 0;
do{
   switch(program[PC]){
	case "UP":
	  print_string("Moving the arm UP!\n");
	  break;
	case "DOWN":
	  print_string("Moving the arm DOWN!\n");
	  break;
	case "LEFT":
	  print_string("Moving the arm LEFT!\n");
	  break;
	case "RIGHT":
	  print_string("Moving the arm RIGHT!\n");
	  break;
	case "CATCH":
	  print_string("Catching an object with the arm!\n");
	  break;
	case "RELEASE":
	  print_string("Releasing the object!\n");
	  break;
   }
   PC++;
} while (program[PC] != STOP);

The Base Program file contains the implementation of two functions to help you on print data on the screen. Call the function print_cmd passing an OPCODE as first argument to print it on the screen. To print strings on the console, use the function print_string passing the address of the string (null terminated) as first argument.

Supplied Files