Reverse Bits on Pentium-Class PCs: Assembly & C Functions

  • Thread starter heman
  • Start date
  • Tags
    Reverse
In summary: Step 6: Return the result.3. Execution Time:To measure the execution time of both the C and assembly language functions, the time related function calls should be used. The functions should be called 50,000 times and the time taken for each function should be recorded.In summary, to write an assembly language function for Pentium-class PCs with the given features, a label and global symbol should be created, the argument should be pushed onto the stack, the bits should be reversed, and the result should be returned. The same behavior can be implemented in a C function by using bitwise operators. To measure the execution time, the functions should be called 50,000 times and the time taken should be recorded using
  • #1
heman
361
0
Can some one guide me ,,how to write an assembly language function for Pentium-class PCs with the following features.

1. C callable.
2. Takes one 32-bit argument
3. Returns 32-bit argument obtained by reversing the bits of the input (i.e. bit 0 of input appears at bit 31, bit 1 at bit 30 and so on).
4. Write another function in C which implements the same behavior.
5. Using the time related function calls, find the time of execution of C function and assembly language function (when the call is made 50000 times).

i just need an general outline..I will be highly thankful for yours help..
 
Technology news on Phys.org
  • #2
1. Assembly Language Function:

The assembly language function should be written in Intel x86 assembly language for Pentium-class PCs, and should be callable from C code. The function should take one 32-bit argument, reverse the bits of the input, and return a 32-bit argument with the reversed bits.

To write the assembly language function:

Step 1: Create a label for the function.

Step 2: Declare the function as a global symbol.

Step 3: Push the argument onto the stack.

Step 4: Load the argument into a register.

Step 5: Reverse the bits of the argument using the appropriate instructions.

Step 6: Store the result in the same register.

Step 7: Pop the result off the stack.

Step 8: Return the result.

2. C Function:

The C function should implement the same behavior as the assembly language function, i.e. it should take one 32-bit argument, reverse the bits of the input, and return a 32-bit argument with the reversed bits.

To write the C function:

Step 1: Declare the function prototype.

Step 2: Create a function definition.

Step 3: Load the argument into a register.

Step 4: Reverse the bits of the argument using the appropriate bitwise operators.

Step 5: Store the result in
 
  • #3


Sure, I can provide some guidance on how to write an assembly language function for Pentium-class PCs that meets the given criteria. Here is a general outline of the steps you can follow:

1. Understand the task: The first step is to understand the task at hand, which is to reverse the bits of a 32-bit input and return the result. This means that the function should take a 32-bit argument as input and return a 32-bit value with the bits reversed.

2. Choose a register: In assembly language, registers are used to store data and perform operations on them. Since we are dealing with a 32-bit value, we need to choose a register that can hold 32 bits. In this case, the EAX register can be used.

3. Load the input: The next step is to load the input argument into the chosen register. This can be done using the MOV instruction, which moves data from one register/memory location to another.

4. Reverse the bits: To reverse the bits, we can use a loop that iterates 32 times (since we are dealing with 32 bits). Inside the loop, we can use the ROR (rotate right) and SHL (shift left) instructions to shift the bits to the right and left, respectively. This will effectively reverse the bits.

5. Store the result: Once the bits are reversed, we need to store the result in a memory location. This can be done using the MOV instruction, similar to how we loaded the input argument.

6. Return the result: In order to make the function C callable, we need to use the RET instruction to return the result to the calling function.

7. Write a C function: Now that the assembly language function is written, we can write a C function that calls this assembly function. The C function should take a 32-bit argument and use the assembly function to reverse the bits and return the result.

8. Measure execution time: To measure the execution time of the C and assembly functions, we can use the time related function calls available in the C standard library. By calling the functions 50000 times and measuring the time before and after the calls, we can calculate the execution time for each function.

I hope this outline helps you in writing the assembly language function and measuring its execution time. Good luck!
 

1. What is the purpose of reversing bits on Pentium-Class PCs?

The purpose of reversing bits on Pentium-Class PCs is to manipulate data at the bit level. This can be useful in various applications such as data encryption or compression.

2. How does the reverse bits function work in assembly language?

In assembly language, the reverse bits function uses bitwise operations to flip the individual bits of a binary number. This is achieved by using logical AND, OR, and XOR operations with a bitmask.

3. What is the advantage of using a reverse bits function in C?

Using a reverse bits function in C allows for a more efficient and portable code. The function can be easily called in different programs and can be optimized for different hardware architectures.

4. Are there any limitations to reversing bits on Pentium-Class PCs?

Yes, there are certain limitations to reversing bits on Pentium-Class PCs. For example, the number of bits that can be reversed at once may be limited by the size of the data type used in the program.

5. Can reverse bits be used for data retrieval on Pentium-Class PCs?

No, reverse bits cannot be used for data retrieval on Pentium-Class PCs. It is primarily used for data manipulation and does not have the capability to retrieve data from memory or storage.

Similar threads

  • Programming and Computer Science
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Programming and Computer Science
2
Replies
60
Views
16K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
6K
Back
Top