[Solved] CS39003 Assignment1

$25

File Name: CS39003_Assignment1.zip
File Size: 178.98 KB

SKU: [Solved] CS39003 Assignment1 Category: Tag:
5/5 - (1 vote)
  1. Translate the following two C programs using GCC/Linux to the assembly language of x86-64 (Intel 64-bit processor) without optimization. Use the following command to generate the assembly code:

gcc -Wall -S <program name>.c

  1. Rename the generated assembly files as ass1a roll.s and ass1b roll.s, where roll is your roll number. Add comments for each line of the assembly language program. Your comment should explain the functionality of the instruction and the connection to the original C program. Also make sure that your commented file can be compiled to generate the executable file. Upload the two files on Moodle server.

Program 1: ass1a.c

#include <stdio.h>

int main()

{ int num1, num2, greater;

num1 = 45; num2 = 68;

if (num1 > num2) greater = num1; else greater = num2;

printf (
The greater number is: %d, greater);

return 0;

}

1

Program 2: ass1b.c

#include <stdio.h>

int GCD (int, int); int GCD4 (int, int, int, int);

int main()

{

int a = 45, b = 99, c = 18, d = 180, result; result = GCD4 (a, b, c, d);

printf (
GCD of %d, %d, %d and %d is: %d,

a, b, c, d, result);

printf (
);

return 0;

}

int GCD4 (int n1, int n2, int n3, int n4)

{ int t1, t2, t3;

t1 = GCD (n1, n2); t2 = GCD (n3, n4); t3 = GCD (t1, t2);

return t3; }

int GCD (int num1, int num2)

{ int temp;

while (num1 % num2 != 0)

{

temp = num1 % num2; num1 = num2; num2 = temp; }

return num2;

}

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS39003 Assignment1[Solved] CS39003 Assignment1
$25