Question

In: Computer Science

Assembly Language HW For this program you will find the largest common factor for 2 numbers,...

Assembly Language HW

For this program you will find the largest common factor for 2 numbers, a and b.

The largest common factor is the largest positive number that divides the two numbers.

The C++ code for doing this is:

int LCF (int a, int b)

{

if (a == 0 && b == 0)

     b = 1;

else

     if (b == 0)

          b = a;

     else

          if (a != 0)

               while (a != b)

                    if (a < b)

                         b -= a;

                    else

                         a -= b;

return b;

}

In your code, you should follow this C++ code as closely as possible.

Read in a and b.

Put a in eax, and b in ebx.

Do not use any loop instructions directly.

Do use compare and jump instructions.

Do not use any procedures except MyProgram.

(the return of an integer from LCF is NOT coded, but replaced with a write of the result

as shown below)

You code should be your work alone.

You example of your console window should look as follows:

Please provide an integer for b: 8

Please provide an integer for a: 4

The largest common factor of a and b is: +4

Solutions

Expert Solution

#include<iostream>

using namespace std;

int helper(int a, int b)

{

if (a == 0 && b == 0)

{

b = 1;

}

else

{

if (b == 0)

          b = a;

     else

{ if (a != 0)

               while (a != b)

{ if (a < b)

                         b -= a;

                    else

                         a -= b;

}

}

}

return b;

}

int main()

{

int eax,ebx;

cout<<"Please provide an integer for b : "<<endl;

cin>>ebx;

cout<<"Please provide an integer for a : "<<endl;

cin>>eax;

int ans=helper(eax,ebx);

cout<<"The largest common factor of a and b is : <<"+"<<ans<<endl;

return 0;

}


Related Solutions

Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE...
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO SOLVE THE EQUATION Z=A+B-(C/D)+E please write the answer separately part A its own code and part B its own code this is microprocessor the ASSEMBLY LANGUAGE emu8086 should be written like this EX: mov ax,100h mov bx,200h etc
In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into...
In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers...
In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
Write an assembly language program for 8051 microcontroller to find the sum of the following series,...
Write an assembly language program for 8051 microcontroller to find the sum of the following series, 1, -2, +3, -4, +5, -6,..., up to 100 terms. Store lower byte in R0 and higher byte in R1.
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called "vdot" that calculates the "dot product" of two vectors "a" and "b", implemented as “arrays” (following the “C” language convention), of 3 elements. the macro should receive 2 pointers to the first element of each vector and return the result in R13.
using Windows 32 bit framework , Write an assembly language program to find the second minimum...
using Windows 32 bit framework , Write an assembly language program to find the second minimum element (formally, second minimum is larger than the minimum but smaller than all the other elements in the array) of an array of size 100. Note: You can define the array as nbrArray DWORD 23 45 21 67 78 95 dup(?) and show that your program works for the first five elements. Display the second minimum in a message box using Input output macro
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Write a program in python language, which accepts 2 numbers and a + sign (for addition)...
Write a program in python language, which accepts 2 numbers and a + sign (for addition) A sign - (for subtraction) A sign * (for multiplication), / (for division) Then calculate and to display the result of the operation he chose with the two numbers. Displaying the appropriate message
The sum of two numbers is 34. a)Find the largest possible product of these numbers.
  1-The sum of two numbers is 34.    a)Find the largest possible product of these numbers.    b)What would be the largest possible product if the sum if the two numbers were "k"? 2-Sixty meters of fencing are used to fence a rectangular garden.    a)Find the dimensions that will give that maximum area.    b)What would be the maximum area if "k" feet of fencing were used in terms of "k"? THANK YOU
Assembly Language for x86 processors You are to write a program which should first ask for...
Assembly Language for x86 processors You are to write a program which should first ask for 4 random numbers from 0-20 (user will inpute these numbers in no preset order). Input these 5 numbers in variables called num1, num2, num3, num4, and num5. When done, your program should sort these numbers (you will use lots of conditions to check order). num1 should contain smallest number while num5 should contain the biggest. display the contents of num1 through num5 on the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT