simple GCC inline assembly code
Budget: $30 – $250 USD
You are responsible to implement several assembly functions to perform the simple arithmetic calculations for 2 64-bit integers. These functions will use the C function signature but the main logic within this function should be inline assembly code using the ASM block similar to the assembly example in the p1sample.cpp
Program Specification:
long mult ( long op1, long op2 )
Can’t use the MUL/IMUL instructions, meaning you use ADD repeatedly
If there are overflow, return the overflowed values in RAX register
long XOR ( long op1, long op2 )
xor will return the result of bit exclusive OR of op1 / op2
can use XOR instruction
long rotate ( long op1, long direction, long number_of_bits )
rotate will perform logical bit-rotation of input operand (op1)
direction = 0 for left and 1 for right
number_of_bits will dictate how many bits to rotate left or right
you need to use rcl and rcr assembly instructions
long factorial ( long op1 )
Input a positive integer (>0) and return the result of op1!
Must use a loop in ASM to compute the result (no recursion)
Summary:
For #1, rewrite mult to use loop. For #2 & #3, write a new function using my examples as a starting point. Uncomment the C code block to test the 2 new functions. For #4, rewrite the factorial C code with inline assembly code using a loop. Remember to add the “q” suffix for 64-bit to the assembly instructions.
Your expected output in this sequence:
Operand 1 = 10 x000000000000000a Operand 2 = 5 x0000000000000005
Add(): 15 x000000000000000f
XOR(): 15 x000000000000000f
Mult(): 50 x0000000000000032
Mod(): 0 x0000000000000000
ShiftL: 320 x0000000000000140
ShiftR: 0 x0000000000000000
RotateL: 320 x0000000000000140
RotateR:-6341068275337658368 xa800000000000000
Fact(): 3628800 x0000000000375f00
Program Specification:
long mult ( long op1, long op2 )
Can’t use the MUL/IMUL instructions, meaning you use ADD repeatedly
If there are overflow, return the overflowed values in RAX register
long XOR ( long op1, long op2 )
xor will return the result of bit exclusive OR of op1 / op2
can use XOR instruction
long rotate ( long op1, long direction, long number_of_bits )
rotate will perform logical bit-rotation of input operand (op1)
direction = 0 for left and 1 for right
number_of_bits will dictate how many bits to rotate left or right
you need to use rcl and rcr assembly instructions
long factorial ( long op1 )
Input a positive integer (>0) and return the result of op1!
Must use a loop in ASM to compute the result (no recursion)
Summary:
For #1, rewrite mult to use loop. For #2 & #3, write a new function using my examples as a starting point. Uncomment the C code block to test the 2 new functions. For #4, rewrite the factorial C code with inline assembly code using a loop. Remember to add the “q” suffix for 64-bit to the assembly instructions.
Your expected output in this sequence:
Operand 1 = 10 x000000000000000a Operand 2 = 5 x0000000000000005
Add(): 15 x000000000000000f
XOR(): 15 x000000000000000f
Mult(): 50 x0000000000000032
Mod(): 0 x0000000000000000
ShiftL: 320 x0000000000000140
ShiftR: 0 x0000000000000000
RotateL: 320 x0000000000000140
RotateR:-6341068275337658368 xa800000000000000
Fact(): 3628800 x0000000000375f00