CPSC355 – Computing Machinery I Solved

$ 20.99
Category:

Description

Assignment 4

Structures and Subroutines

Create an ARMv8 assembly language program that implements the following program:

#define FALSE 0
#define TRUE 1
struct point { int x, y;
};
struct dimension { int width, height;
}; struct box { struct point origin; struct dimension size; int area;
};

struct box newBox()
{
struct box b;

b.origin.x = 0;
b.origin.y = 0;
b.size.width = 1;
b.size.height = 1;
b.area = b.size.width * b.size.height; return b;
}

void move(struct box *b, int deltaX, int deltaY)
{
b->origin.x += deltaX; b->origin.y += deltaY;
}

void expand(struct box *b, int factor)
{
b->size.width *= factor; b->size.height *= factor;
b->area = b->size.width * b->size.height;
}

void printBox(char *name, struct box *b)
{
printf(“Box %s origin = (%d, %d) width = %d height = %d area = %d “,
name, b->origin.x, b->origin.y, b->size.width, b->size.height, b->area);
}

int equal(struct box *b1, struct box *b2) {
int result = FALSE;

if (b1->origin.x == b2->origin.x) { if (b1->origin.y == b2->origin.y) { if (b1->size.width == b2->size.width) { if (b1->size.height == b2->size.height) { result = TRUE;
}
}
}
}
return result;
}
int main() {
struct box first, second;

first = newBox(); second = newBox();

printf(“Initial box values: “); printBox(“first”, &first); printBox(“second”, &second);

if (equal(&first, &second)) { move(&first, -5, 7); expand(&second, 3);
}
printf(” Changed box values: “); printBox(“first”, &first); printBox(“second”, &second);
}

Also run the program in gdb, displaying the values of first and second after they have been set by function calls. You should show that the functions are working as expected. Capture the gdb session using the script UNIX command, and name the output file script.txt.

Other Requirements

Make sure your code is readable and fully documented, including identifying information at the top of each file. You must comment each line of assembly code. Your code should also be well designed: make sure it is well organized, clear, and concise.

New Skills Needed for this Assignment:

• Implementation of structs and nested structs
• Implementation of subroutines in assembly
• Returning structs by value from functions
• Use of pointers as arguments to subroutines

Submit the following:

Be sure to name your program and script file as described above.
Computing Machinery I
Assignment 4 Grading

Student:__________________________________________

Functionality

newBox() function
8 ______
move() function
4 ______
expand() function
6 ______
equal() function
6 ______
printBox() function
6 ______
main() function
8 ______
Correct implementation of structs
4 ______
Correct use of stack variables
4 ______
Script showing gdb session
2 ______
Complete documentation and commenting
4 ______
Design quality

2 ______
Total 54 ______ _____%

Reviews

There are no reviews yet.

Be the first to review “CPSC355 – Computing Machinery I Solved”

Your email address will not be published. Required fields are marked *