Lab11

.docx

School

University of Massachusetts, Lowell *

*We aren’t endorsed by this school

Course

2030

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

3

Uploaded by BarristerRoseMouse35

Report
COMP.2030 LAB 11/29/23 NAME _____________________________________________ 1. A recursive C function, recur , is declared as int recur(long *x, long y) is compiled into the x86 code on the right. Complete the C code of the function recur below. int recur( long *x, long y) { recur: pushq %rbp movq %rsp, %rbp subq $16, %rsp movq %rdi, -8(%rbp) movq %rsi, -16(%rbp) cmpq $0, -8(%rbp) jne .L2 movl $-1, %eax jmp .L3 .L2: cmpq $10, -16(%rbp) jne .L4 movl $0, %eax jmp .L3 .L4: movq -8(%rbp), %rax movq (%rax), %rax cmpq -16(%rbp), %rax jle .L5 movq -8(%rbp), %rax addq $8, %rax movq (%rax), %rax movq -16(%rbp), %rdx movq %rdx, %rsi movq %rax, %rdi call recur addl %eax, %eax jmp .L3 .L5: movl $1, %eax .L3: leave ret
2. The function long switch_prob(long x, long n) is disassembled as shown below. long switch_prob(long x, long n) { long result = x; switch(n) {
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help