Assume that we are using the x86-64 architecture
Convert the following code fragment (in the C
language) to assembly code.
Explain your steps. [25 marks]
long test ( long a, long b, long c ) {
long t;
if (a>b) {
if (a>c)
t=a;
else
t=c;
} else {
t=b;
}
return t;
}
Assume that we are using the x86-64 architecture Convert the following code fragment (in the C...
Question 2 Assume that we are using the x86-64 architecture, as mentioned in lecture 4. 2(a) Explain the meaning of the following instruction: movq %rbx, (%rcx) State your assumptions of the content in registers and memory, before executing this instruction. What will happen after executing this instruction? (b)Convert the following code fragment (in the C language) to assembly code. Explain your steps. [25 marks] long test ( long a, long b, long c ) { long t; if...
Convert the following C fragment to equivalent MIPS assembly language. Assume that the variables a, b, c, d, i and x are assigened to registers $t1, $t2, $t3, $t4, $s0 and $s1 respectively. Assume that the base address of the array A and B is in register $a0 and $a1 respectively. if (a > 0) b = a + 10; else b = a - 10;
Convert the following C/C++ fragment into equivalent MIPS assembly language. Assume that the variables a, b, c, d, i and x are assigned to registers $t1, $t2, $t3, $t4, $s0 and $s1 respectively. if ((a<b && (c == 0) d = 1;
Convert the following c code into instructions MIPS Assembly language. Assume a associated with $s0, i with $s1, and j with $s2. if( i < 10) { if( j < 10) { a = 0; } else { a = 1;} } else { a = 2; }
a) Write the following C function in Assembly. You must follow the System V 64-bit calling convention and use AT&T Syntax notation. long fibonacci (long n) { if (n == 0) return 0; else if (n == 1) return 1; else return (fibonacci (n - 1) + fibonacci (n - 2)); } b) The Windows x86-64 calling convention passes function parameters in the registers RCX, RDX, R8 and R9 and returns values on register RAX. Caller saved registers are: RAX,...
C++ READ CODE: 8. Below is a code fragment; assume x is an integer with the value 40 at the start of the code fragment. Execute each code fragment and show the output below that code fragment. if (x 25) if (x 0) x=x*2; x=x+1; else ( x1i cout < xi
3. Convert the following C code to assembly. Assume a, b, and c are in main memory at addresses 1000, 1004, and 1008. if(a == 20) b=c+10; else b = c-14;
a) Write the following C function in Assembly. You must follow the System V 64-bit calling convention and use AT&T Syntax notation. Note: You cannot change the algorithm in any way so your assembly function must still be recursive. (20 points) long Catalan(long n) { long sum = 0; if (n == 0) return 1; for (int i = 0; i < n; i++) { sum += Catalan(i) * Catalan(n - i - 1); } return sum; } b) The...
39. Rewrite the following C code segment in x86 (assume bs kebx) x86 switch (b) case 1 case 2: case 3: default: return Walpha" return "beta" return gamma" return "delta" 40. Does the following function definition qualfy as a leaf function? Why or why not? int quadratic(int x, int a, int b, int c) return a square (x) b 41. Assuming the GCC calling conventions are being used, what instructions always start the prolog of a function? 42. Assuming the...
01) Write PIC24 assembly language equivalents for the Sollowing C code fragments. Assume variables u16 iul kal6 j.ul6 n are uintl6 variables, while uš p, u8 q, u8 rare uin variables 1. Code fragent 2. Code fragment . Code frapent (use place holders for if-body, else-body) if-body statements else-body statements 4. Code fragent (use place holders for if-body, else-body) if-body statements l else I else-body statenents 5. Code frapent (use place holders for loop-body) &. Code fragent (use place holders...