Question

In: Computer Science

Write a C program that defines int minimum (int ji, int j2) which returns the smaller...

Write a C program that defines

int minimum (int ji, int j2)

which returns the smaller of j1 and j2. (a) Write your program with a global variable for the actual parameter. Translate your C program to Pep/9 assembly language. (b) Write your program with a local variable for the actual parameter. Translate your C program to Pep/9 assembly language.

Solutions

Expert Solution

(a)Write your program with a global variable for the actual parameter.

#include <stdio.h>
#define n 11
void main ()
{
  int i,j,m,k, max, min;
  int Array[n];
  clrscr();
  printf("Enter %d integers:", n);
  for(i=0; i<n; i++)
    scanf("%d", & Array [i]);
    printf("\nyou have entered the following numbers: \n");
    for( j =0;j<n;j++)
      printf("%d ",Array [j]);
      printf ("\n");
      max= Array [0];
       {
          for(k =0;k<n;k++)
            if(Array [k]>max)
               max= Array [k];
            else max = max;
       }
            printf("Maximum number is = %d\n",max);
            min= Array [0];
            {
              for(m =0;m<n;m++)
                if(Array [m]<min)
                  min= Array [m];
                else min = min;
            }
            printf("Minimum number= %d\n",min);

(b) Write your program with a local variable for the actual parameter.

#include <stdio.h>


int max(int num1, int num2);
int min(int num1, int num2);

int main()
{
int num1, num2, maximum, minimum;
  printf("Enter any two numbers: ");
scanf("%d%d", &num1, &num2);
  
maximum = max(num1, num2);  
minimum = min(num1, num2);
  
printf("\nMaximum = %d\n", maximum);
printf("Minimum = %d", minimum);
  
return 0;
}

Translate your C program to Pep/9 assembly language.

convert this codes to pep/9 by writing in cmd : -

$ gcc -S filename.c

(save codes as "filename" or anythin you want)


Related Solutions

Write a C++ function which takes an int array and its size as parameters. It returns...
Write a C++ function which takes an int array and its size as parameters. It returns an int indicating how many multiples of 3 are contained in the array. For example, if the array contains {2, 6, 8} your function should return 1. If the array contains {3, 10, 5, 6} your function should return 2. Here is the function prototype: // int array[]: array to search // size: number of elements in the array int countMult(const int array[], int...
Write a complete C++ program that defines, implements, and utilizes a Lion class and a Pine...
Write a complete C++ program that defines, implements, and utilizes a Lion class and a Pine class. Definition of classes from the implementation of the classes should be split. The program is made of five files: Lion.h, Lion.cpp, Pine.h, Pine.cpp, and TestLionPine.cpp. The components of Lion class are defined in the Lion.h file; however, all constructors and methods should not have any implementation code in this header file. All implementation code, i.e. constructor body and method body, should be written...
write a c++ program. Define a class ‘Matrix’ which contain 2D int array ‘m’ of size...
write a c++ program. Define a class ‘Matrix’ which contain 2D int array ‘m’ of size 3x3 as private member.        There should be two public methods within the class definition namely: void setMatrixValue(int i, int j); that should set m[i][j] with user defined values int getMatrixValue(int i, int j); that should return m[i][j] Make a global function named ‘CrossProduct(Matrix m1, Matrix m2)’ that should compute the marix multiplication
Write a C++ program test.cpp. The class should contain a protected int member variable var, which...
Write a C++ program test.cpp. The class should contain a protected int member variable var, which is initialized with an integer value between 1 and 50 in a constructor that takes an integer parameter. The class should contain a public member function called play that should print out a sequence of integers as a result of iteratively applying a math function f to the member variable var. The function f is defined as f(x) = (3x+1)/2 if x is odd...
Write a program fragment (not a complete program) which will perform the following task: The int...
Write a program fragment (not a complete program) which will perform the following task: The int variable m currently contains the number of minutes a basketball player played in their last game. Use an IF statement(s) to print out an appropriate message based on the following: If m is from 35 to 48, print the message "very tired" If m is from 10 to 34, print the message "little tired" If m is from 1 to 9, print the message...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
C++ The minimum function. (a) Write a function that takes two integers and returns the value...
C++ The minimum function. (a) Write a function that takes two integers and returns the value of the smaller one. In the main() function provide 5 test cases to verify its correctness. (b) Write the function that takes two characters and return the smaller one in the lexicographical order. Write the main() function that tests that functions for 5 different pairs of character type variables. (c) Write a generic function that takes two numeric objects and returns the value of...
write a C++ Program for matrix operations which include: 1. constructor in the form-- matrix::matrix(int numRows,...
write a C++ Program for matrix operations which include: 1. constructor in the form-- matrix::matrix(int numRows, int numColumns) 2. Implement a setter method of the form: -- void matrix::setElement(int row, int col) 3 Implement a getter method of the form: -- float matrix::getElement(int row, int col) 4. Make a threaded version of the matrix/matrix addition method. 5. Make a threaded version of the matrix/scalar multiplication method. 6. Matrix/matrix addition methods of the form: -- matrix matrix::matrixAdd(matrix inMatrix) // non-threaded version...
Submit a c++ file: 2. Write a program that defines the named constant PI, const double...
Submit a c++ file: 2. Write a program that defines the named constant PI, const double PI = 3.14159;, which stores the value of p. The program should use PI and the functions listed in Table 6-1 to accomplish the following: a. Output the value of Pi Output the value of Pi. b. Prompt the user to input the value of a double variable r, which stores the radius of a sphere. The program then outputs the following: i.   The...
Write a program in C that declares the following array: int. array[] = { 1, 2,...
Write a program in C that declares the following array: int. array[] = { 1, 2, 4, 8, 16, 32 } Then write some code that accepts a number between 0 and 5 from the user and stores it in a variable called "index". Write some code that retrieves the item specified by the index, like this: int item = array[index]; Then write code that outputs the corresponding array entry based on the number the user entered. Example output: The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT