Write an assembly function equivalent to the following C function. If X[k] > K[k+1], it swaps X[k] and X[k+1] and returns 1; otherwise, it returns 0. You may use either conditional branch or conditional execution or their combination.
int swap(unsigned short X[], int k)
if (X[k] > X[k+1]) {
short tmp = X[k];
X[k+1] = X[k];
X[k] = tmp;
return 1;
else {
return 0;
Write an assembly function equivalent to the following C function. If X[k] > K[k+1], it swaps...
write a function in C that swaps every other byte: for example, Input: "badcfe” Output: abcdef I was thinking something like , where len would be two since I just want to swap values next to each other, but this doesnt work. void swap(char *p, int len) { int i; char tmp; for(i = 0; i < len/2; i++) { tmp = p[len-i-1]; p[len-i-1] = p[i]; p[i] = tmp; } }
avr assembly please 3) Write an assembly program that is algorithmically equivalent to the following C++ code. Treat the variable y as a short int (16 bits) 1 int y; 2 for (int x = 2; x <= 20; x = x + 2) { 3 ¡f (x < 18) { 4 5 у 24 6 else f 7 8 9 3) Write an assembly program that is algorithmically equivalent to the following C++ code. Treat the variable y as...
White a function that swaps values using templates int main ( ) { int X=5 int Y=29 ; double a = 1.0 ; double b = 3.14 ; swap ( X , Y ) ; swap ( a , b ) ; return 0 ; } I need you to explain it step by step
2) Write an assembly program that is algorithmically equivalent to the following C+t code Consider the variables to be 8-bit unsigned integers; you may initialize them to any values 0-255 if you like for testing purposes 13 int speed, lower, a, b; 14 15 if (speed < 98) { 16 17 if (speed <80) t 18 lower++; 19 20 21 else f 23 24 25 26 else t 27 28 2) Write an assembly program that is algorithmically equivalent to...
Below is a C function and a first attempt at translating it into equivalent ARM subroutine. However, while the ARM code assembles successfully, execution of it reveals that it regularly gets stuck within fact in what is apparently an infinite loop. Explain why and explain how you can repair the ARM code so that it returns correctly while preserving the recursive nature of the original C function. int fact(int n) { if (n == 0) { return 1; } else...
*Write a function that returns 0 if x is 0, returns -1 if x < 0, returns 1 if x > 0 *Your code must follow the Bit-Level Integer Coding Rules *You can assume w = 32. *The only allowed operations in your code are: ! ~ & ^ | + << >> *This requirement is more restrictive than the coding rules. *You cannot use if-else statement, switch, loops, and comparison operators( <,>) int sign(int x) { return 0;...
C++ Write a function SwapArrayEnds() that swaps the first and last elements of the function's array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}. The array's size may differ from 4. #include <iostream> using namespace std; /* Your solution goes here */ int main() { const int SORT_ARR_SIZE = 4; int sortArray[SORT_ARR_SIZE]; int i = 0; sortArray[0] = 10; sortArray[1] = 20; sortArray[2] = 30; sortArray[3] = 40;...
write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...
I am stuck on trying to get this recursive function's logic to make it work. //Write a recursive function that returns true if the sequence of 0 < n integers in A is sorted in non-increasing order and false otherwise. iostream and cmath libraries only bool is_sorted(const int *A, unsigned int n){ if (n == 0) return false; if (A > A+1) return true; else return false; }
Write an (efficient) pseudocode for the implementation of each of the following function prototypes (proper C code will also be accepted) - void print(Q) – prints the entire queue Q from front to back. - int enqueue(Q,x) – enqueues the element x into queue Q (if unsuccessful, return -1) - int* dequeue(Q) – dequeues the next integer from front of the queue (if unsuccessful, return null) - int isEmpty(Q) – returns 1 (true) or 0 (false) depending on emptiness of...