fibonacci(long):
addiu $sp,$sp,-40
sw $31,36($sp)
sw $fp,32($sp)
sw $16,28($sp)
move $fp,$sp
sw $4,40($fp)
lw $2,40($fp)
nop
bne $2,$0,$L2
nop
move $2,$0
b $L3
nop
lw $3,40($fp)
li $2,1 # 0x1
bne $3,$2,$L4
nop
li $2,1 # 0x1
b $L3
nop
lw $2,40($fp)
nop
addiu $2,$2,-1
move $4,$2
jal fibonacci(long)
nop
move $16,$2
lw $2,40($fp)
nop
addiu $2,$2,-2
move $4,$2
jal fibonacci(long)
nop
addu $2,$16,$2
move $sp,$fp
lw $31,36($sp)
lw $fp,32($sp)
lw $16,28($sp)
addiu $sp,$sp,40
j $31
nop
a) Write the following C function in Assembly. You must follow the System V 64-bit calling...
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...
Assembly language 64 bit please !
An example file for set up
==========+
;| Data Segment BEGINS Here |
;+======================================================================+
segment .data
;Code this expression: sum = num1+num2
num1 dq 0 ;left operand of the addition operation
num2 dq 0 ;right operand of the addition operation
sum dq 0 ;will hold the computed Sum value
RetVal dq 0 ;Integer value RETURNED by function calls
;can be ignored or used as determined by the programmer
;Message string prompting for the keyboard...
May you explain how you got the answer
The following code sequence occurs near the beginning of the assembly code generated by gcc for a c procedure: 9. 1, subq 2" movq 3" movq 4" movq 5. movq 6. movq 7. movq 8. movq 9. movq 10. movq $24,%rsp %rbx, (%rsp) %r12, 8(%rsp) %r13, 16(%rsp) 16(%rbp), %rbx 24(%rbp), %r13 (%rbx), %r12 (%r13), %rax 16(%rbp ) ,%rdx (%rdx), %rcx we see that just three registers (%rbx, %r12 and %r13) are saved...
Write the C Code for the Intel assembley below. Note: Don't copy and paste anything from github because it won't be the right answer. .file "mystery.c" .comm num,1600,32 .text .globl add .type add, @function add: .LFB2: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movq %rdi, -8(%rbp) movq %rsi, -16(%rbp) movq -16(%rbp), %rax movq -8(%rbp), %rdx addq %rdx, %rax popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE2: .size add, .-add .globl dothething .type dothething, @function...
You know the following assembly code snippet is from a recursive function in C. You also know that the stack contents at a particular point in time when we are in the recursive function are shown on the next page. Answer the following questions: a) how many Foo stack frames are on the stack? b) what is the return address back to the function that called Foo for the first time? c) what is the return address back into the...
Consider the following source code, where b, c, and d are constants declared with #define. You will need to determine the values for b, c, and d. struct lnode { char *str; struct lnode *next; } struct lnode A[b][c][d]; int store_ele(int h, int i, int j, struct lnode dest) { A[h][i][j] = dest; return sizeof(A);} On compiling this program (with -O2), GCC generates the following assembly code for the store_ele function: store_ele: movslq %edi, %rdi movslq %esi, %rsi movslq %edx,...
Assembly Language 64- bit system Description: 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 shown in class. 1. long XOR ( long op1, long op2 )- xor will return the result of bit exclusive OR of op1 / op2- can use...