# CPSC355 Computing Machinery I Assignment 2 Solved

25.00 \$

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . ` zip` solution files instantly, after Payment

## Description

5/5 - (1 vote)

Â Integer Multiplication using Add and Shift Operations

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

#include <stdio.h>

#define FALSE 0

#define TRUEÂ  1

int main() {

int multiplier, multiplicand, product, i, negative;Â Â  long int result, temp1, temp2;

// Initialize variablesÂ Â  multiplicand = -16843010;Â Â  multiplier = 70;Â Â  product = 0;

// Print out initial values of variables

printf(“multiplier = 0x%08x (%d)Â  multiplicand = 0x%08x (%d)\n\n”,Â  Â  Â multiplier, multiplier, multiplicand, multiplicand);

// Determine if multiplier is negativeÂ Â  negative = multiplier < 0 ? TRUE : FALSE;

// Do repeated add and shiftÂ Â  for (i = 0; i < 32; i++) {

if (multiplier & 0x1) { // If LSB mplier ==1: (If (nonzero))Â Â Â Â Â Â  product = product + multiplicand;

}

// Arithmetic shift right the combined product and multiplierÂ Â Â Â  multiplier = multiplier >> 1;Â Â Â Â  if (product & 0x1) { // If LSB product == 1Â Â Â Â Â Â  multiplier = multiplier | 0x80000000;

} else {

multiplier = multiplier & 0x7FFFFFFF;

}

product = product >> 1;

}

// Adjust product register if multiplier is negativeÂ Â  if (negative) {

product = product – multiplicand;

}

// Print out product and multiplierÂ Â  printf(“product = 0x%08xÂ  multiplier = 0x%08x\n”,Â  Â Â Â Â  Â product, multiplier);-168

// Combine product and multiplier togetherÂ Â  temp1 = (long int)product & 0xFFFFFFFF;Â Â  temp1 = temp1 << 32;

temp2 = (long int)multiplier & 0xFFFFFFFF;Â Â  result = temp1 + temp2;

// Print out 64-bit result

printf(“64-bit result = 0x%016lx (%ld)\n”, result, result);

return 0; }

Be sure to use 32-bit registers for variables declared using int, and 64-bit registers for variables declared using long int. Use m4 macros to name the registers to make your code more readable. Name the program assign2a.asm. Optimize your code so that it uses as few instructions as possible.

Also run the program in gdb, displaying the contents of key registers as the program executes; you should show that the algorithm is working as expected. Capture the gdb session using the Unix command script and name the output file script.txt.

Create a second version of the program (called assign2b.asm) that uses 522133279 for the multiplicand, and 200 for the multiplier. Also create a third version of the program (called assign2c.asm) that uses -252645136 for the multiplicand, and -256 for the multiplier.

Other RequirementsÂ

Make sure your code is properly formatted into columns, is readable and fully documented, and includes 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:

• Use of bitwise logical and shift operations
• Use of branching and condition code tests
• Understanding of hexadecimal and binary numbers

Submit the following:

Â

1. Your assembly source code files for the 3 programs, and your script output file. Use the Assignment 2 Dropbox Folder in D2L to submit electronically. The TA will assemble and run your programs to test them. Be sure to name your programs and script file as described above.

• Assignment2.zip