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
The BasicSet 2 class implements the Set ADT by wrapping an object of the Linked Collection class and:______.
Trava [24]

Answer:

The BasicSet 2 class implements the Set ADT by wrapping an object of the Linked Collection class and forwarding" all method calls except certain calls to the add method.

8 0
3 years ago
I'm trying to move the figure a little away from, the column line and every time I move it and click ok it goes back to being be
Luba_88 [7]

Answer:

Try to click the center button layout.

Explanation:

8 0
3 years ago
You are trying to connect a new USB device to your computer. You install the driver and then connect the device to an open USB
nadezda [96]

Answer:

By order of increasing magnitude:

D. Make sure the USB device is plugged in properly.

A. Try a different USB cable.

B. Replace the USB device.

C. Install a new USB controller card.

Explanation:

Start with whatever is simplest first. Most errors are simply ID-10-T mistakes.

3 0
2 years ago
toThePowerOf is a method that accepts two int arguments and returns the value of the first parameter raised to the power of the
inessss [21]

Answer:

cubeVolume = toThePowerOf(cubeSide, 3)

Explanation:

The function toThePowerOf, receives two int arguments say, a and b, where a is the first argument and b is the second argument as follows:

toThePowerOf(a,b)

The function returns the first argument(a) raised to the power of the second argument (b) i.e a ^ b as follows:

toThePowerOf(a, b){

return a^b

}

In the call to the function, the first argument a, is replaced with the variable cubeSide and the second argument b is replaced with the value 3.

Hence, the returned result becomes cubeSide ^ 3 which is then stored in a variable cubeVolume as follows:

cubeVolume = toThePowerOf(cubeSide, 3)

6 0
2 years ago
There are 12 inches in a foot and 3 feet in a yard. Create a class named InchConversion. Its main() method accepts a value in in
Dafna1 [17]

Answer:

import java.util.Scanner;

public class InchConversion

{

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

   

 System.out.print("Enter inches: ");

 double inches = input.nextDouble();

 

 inchesToFeet(inches);

 inchesToYards(inches);

}

public static void inchesToFeet(double inches){

    double feet = inches / 12;

    System.out.println(inches + " inches = " + feet + " feet");

}

public static void inchesToYards(double inches){

    double yards = inches / 36;

    System.out.println(inches + " inches = " + yards + " yards");

}

}

Explanation:

In the inchesToFeet() method that takes one parameter, inches:

Convert the inches to feet using the conversion rate, divide inches by 12

Print the feet

In the inchesToYards() method that takes one parameter, inches:

Convert the inches to yards using the conversion rate, divide inches by 36

Print the yards

In the main:

Ask the user to enter the inches

Call the inchesToFeet() and inchesToYards() methods passing the inches as parameter for each method

7 0
2 years ago
Other questions:
  • The purpose of hazard lights is to
    7·2 answers
  • Is Digital technology always better or should we champion or even return to innovative of analog machines and experiences? Apex
    13·1 answer
  • Multiple systems try to send data at the same time. The electrical impulses sent across the cable interfere with each other. Wha
    15·1 answer
  • Browsing the web is one of the most common activities performed by individuals who use computers.
    12·1 answer
  • Which would be included in a SaaS platform?<br><br> A.data link<br> B.IaaS<br> C.Java<br> D.vb.net
    5·1 answer
  • Which of the following operation is not performed by a mouse 1) left click , middle click , right click, double click​
    15·2 answers
  • What do u think a creative app must have? <br><br> Please answer the question ASAP!!
    5·1 answer
  • Write short notes about monitor printer and speaker​
    14·2 answers
  • A natural language processor reads the sentence The walk was tiring and mistakes the noun “walk” as a verb. What is such an erro
    13·1 answer
  • I want the answer of this task ( using prolog language ) ASAP because the deadline is tomorrow. Please help :"
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!