1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anuta_ua [19.1K]
3 years ago
10

Write a C function which mimics the behavior of the assembly language function below. Note that this time, the assembly language

code is recursive (despite –O2 compilation), and your C code should likewise be recursive.
f:
cmpl $1, %edi
je .L3
xorl %eax, %eax
testl %edi, %edi
jle .L7
subq $8, %rsp
subl $1, %edi
call f
testl %eax, %eax
sete %al
addq $8, %rsp
movzbl %al, %eax
.L7:
ret
.L3:
movl $1, %eax
ret
Computers and Technology
1 answer:
Digiron [165]3 years ago
6 0

Answer:

#include <stdio.h>

int f(int edi) {

 

  if (edi == 1) {

      return 1;  

  }

  if (edi <= 0) {

      return 0;

  }

 

  edi--;

  int eax = f(edi);

 

  if(eax == 0) {

      return 1;

  } else {

      return 0;

  }

}

int main(void) {

  int edi = 9;

  int ret;

  ret = f(edi);

  printf("%d", ret);

  return 0;

}

Explanation:

  • Inside the function f, check if edi is 1 or less than 1 and then return a number accordingly.
  • Decrement the edi variable, call the f function and assign its value to eax.
  • Check if eax is equal to 0 then return 1 else return 0.
  • Inside the main function, call the f function by passing the edi value and finally display the value of ret.
You might be interested in
Web services can exchange information between two different systems only if the operating systems and programming languages upon
stich3 [128]
Because if im talking to someone in english but they are from china and communicating to me in chinese then thas what itll do
4 0
2 years ago
What icon might you see in device manager that indicates a problem with a device?
Nataly_w [17]
A yellow triangle with a exclamation mark might appear if a problem is detected with the device. Of course, this is different depending on the version of Windows you have.
7 0
3 years ago
A major advantage of longitudinal design over the cross-sectional design is the ability to detect change as a result of repeated
sattari [20]

Answer:

True is the correct answer to the given question .

Explanation:

In the longitudinal analysis of designing we are collecting the information from the similar sample frequently over an enlarged time where as in the cross-sectional analysis designing Gathering the information from the population at the given time interval .

The main objective longitudinal designed is used to monitor the variations in the similar sample as a result of frequent analysis of the similar variables that are not possible in the cross-sectional design analysis .

Therefore the given statement is true .

5 0
2 years ago
A day has 86,400 secs (24*60*60). Given a number in the range 1 to 86,400, output the current time as hours, minutes, and second
stellarik [79]

Answer:

Here it the C++ program:

#include <iostream> //to use input output functions in the program

using namespace std; // to identify objects like cin, cout

int main() { //start of the body of main() function

   int time = 0; // time entered by the user

   int hour = 0; // to hold the value of hours

   int min = 0; //to hold the value of minutes

   int sec = 0; // to hold the value of seconds

   int remaining_time=0; // holds value of remaining time while conversion

cout << "Enter a time in seconds: "; //Prompts user to enter time in secs

cin >> time; //reads the value of time entered by the use

hour = time/3600; //divides the input time to 3600 to convert in hours

remaining_time = time%3600; // to calculate remaining time

min = remaining_time/60; // divides remaining time with 60 to get mins

remaining_time = remaining_time%60;

/* computes remaining time after converting the previous remaining time to minutes. */

       sec = remaining_time; // computes no of seconds

// time entered by user should be within this range

     if(time>=1 && time<=86400)

/*when if condition is true it displays the input seconds to hours minutes and seconds */

{cout<<"\nThe time is: "<<hour<<" hours, " <<min<<" minutes, and "<<sec<<" seconds\n"; }

else //when if condition evaluates to false

cout<<"Out of range";  } //displays out of range message

Explanation:

Everything is briefly explained in the comments given within the program.

The logic of this program is explained below.

Lets see how the given example works with this program. Suppose the user enters 96500. The message out of range is displayed as this value exceeds the range 1 to 86400.

Suppose user enters 70000. If condition evaluates to true. So this number is converted into hours, minutes as seconds as following:

To calculate hours this formula is used

                          hour = time/3600;

                                   = 70000/3600

                                   = 19

So the value of hour=19

Now the remaining_time variable works as a temporary variable to hold the remaining input after calculation of each conversion.

So after conversion to hour the remaining_time value is calculated as:

                         remaining_time = time%3600;

                                                    = 70000%3600

                                                    = 1600

mod here finds the remainder after conversion to hours as 70000/3600 has quotient 19 and remainder 1600.

Now the value of minutes is computed by this remaining time (value stored in remaining_time).

                       min = remaining_time/60;

                                     = 1600/60

                                     = 26

So the value of minutes is 26

Lets calculate remaining time:

                    remaining_time = remaining_time%60;

                                               = 1600%60

                                               = 40

Now the new value stored in remaining_time is 40

Now lets find the value of seconds:

                      sec = remaining_time;

                             = 40

As the new value of remaining_time is 40 so seconds=40

Finally the following message is displayed in output:

The time is: 19 hours, 26 minutes, and 40 seconds

5 0
2 years ago
Which processor that manipulate graphic data to form images on a monitor screen?
vladimir1956 [14]
A graphics processing unit. (GPU)
6 0
3 years ago
Read 2 more answers
Other questions:
  • What are a few benefits of virtualization?<br> How do they benefit ?
    9·1 answer
  • What do you call the combination of title, description, tags, and thumbnail?
    6·1 answer
  • What is the output of the following function if the array nums contains the values 1 2 3 4 5 int backwards(int nums[]) { for (x
    15·1 answer
  • Write a java program which uses methods for calculating the sum of any 5 non-zero integer digits that are input. The program mus
    8·1 answer
  • List the step in turning on a computer
    6·1 answer
  • Visual culture is an area of academic study that deals with the totality of images and visual objects produced in ____________,
    6·1 answer
  • Write a program that administers and grades quizzes. A quiz consists of questions. There are four types of questions: text quest
    13·1 answer
  • Hi wanna play fortnite tomorrow add me im batjoker09 no caps or spaces
    13·1 answer
  • Write a method, findMax(), that takes in two integers and returns the largest value. Ex: If the program input is: 4 2 the method
    8·1 answer
  • Why do designers of smartphones hide computer processing details from
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!