Question
The purpose of this assignment is for you to become better at comprehending x86-64 assembly language. Rather than writing assembly language programs, your task in
The purpose of this assignment is for you to become better at comprehending x86-64 assembly language. Rather than writing assembly language programs, your task in this assignment is to reverse engineer x86-64 code into C. Specifically, you will find 5 functions in a file called hw4.s , and your job is to write 5 equivalent functions in C. Each correct answer is worth 2 points. Please turn in your C code in a file called hw4.c
Your C code does not have to compile into exactly the same .s code that I have given you. Rather, you will be graded on whether or not your C functions properly emulate the assembly language; that is, they both should return the same value provided they are passed the same values as parameters.
f1: subl $97, %edi xorl %eax, %eax cmpb $25, %dil setbe %al ret
f2: cmpl %edx, %edi sete %dl xorl %eax, %eax cmpl %esi, %edi sete %al andl %edx, %eax ret
f3: cmpl $1, %edi jle .L6 movl $2, %edx movl $1, %eax jmp .L5 .L8: movl %ecx, %edx .L5: imull %edx, %eax leal 1(%rdx), %ecx cmpl %eax, %edi jg .L8 .L4: cmpl %edi, %eax sete %al movzbl %al, %eax ret .L6: movl $1, %eax jmp .L4
f4: pushq %r12 movq %rdi, %r12 pushq %rbp movq %r12, %rbp pushq %rbx leaq 1(%r12), %rbx call puts movsbl (%r12), %edx testb %dl, %dl je .L15 .L17: xorl %eax, %eax movl $122, %ecx movl $97, %esi movl $.LC0, %edi call printf movzbl 0(%rbp), %edx leal -97(%rdx), %eax cmpb $25, %al ja .L11 subl $32, %edx movb %dl, 0(%rbp) .L11: movq %rbx, %rbp addq $1, %rbx movsbl -1(%rbx), %edx testb %dl, %dl jne .L17 .L15: popq %rbx popq %rbp movq %r12, %rax popq %r12 ret
f5: cmpb $0, (%rdi) movq %rdi, %rax movq %rdi, %rdx je .L32 .L22: addq $1, %rdx cmpb $0, (%rdx) jne .L22 movzbl (%rsi), %ecx testb %cl, %cl je .L33 .L24: movb %cl, (%rdx) addq $1, %rsi addq $1, %rdx .L32: movzbl (%rsi), %ecx testb %cl, %cl jne .L24 .L33: movb $0, (%rdx) ret
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started