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

Write an Intel 8085 assembly program to find the largest of N numbers stored in memory...
Write an Intel 8085 assembly program to find the largest of N numbers stored in memory using the algorithm below. Hand trace (execute) the program showing the changes made to all affected registers and memory locations. Max = a(1) For i = n to N If max < a(i) then max = a(i) Next i
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 assembly language program that repeatedly prompts the user to enter signed decimal integer numbers....
Write an assembly language program that repeatedly prompts the user to enter signed decimal integer numbers. The program should be run from the command prompt, output a text prompt to the screen, and then wait for the user to type in a number followed by the Enter key. (The legitimate range of user input values is any signed integer that can be represented in 32 bits.) After each number is entered, the program should determine and display the following information...
Using assembly code, given these numbers: 09 11 1F 20 06 F0 Find the largest value?
Using assembly code, given these numbers: 09 11 1F 20 06 F0 Find the largest value?
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N + 3 && (C == ‘N’ || C == ‘n’)) C = ‘0’; else C = ‘1’; Assume that M and N are 32-bit signed integer variables, and C is an 8-bit ASCII character variable. All variables are stored in memory, and all general-purpose registers are available for use.
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT