In this assignment, you will \"reverse engineer\" several x86-64 assembly langua
ID: 3840904 • Letter: I
Question
In this assignment, you will "reverse engineer" several x86-64 assembly language functions. The goal is to increase your knowledge of assembly language and help you develop the ability to read assembly language code and understand what it does.
Your task: You will find a file called hw5.s , which contains x64 (assembly language) implementations of 9 functions. They are called f1, f2, f3, etc. I generated hw5.s by running gcc on my own C source code, using the –S and –O2 flags. Your task is to write C implementations of these 9 functions, so that your C code emulates the assembly language versions. Each C function that you write will be counted as correct if your function returns the same value as its assembly language version, provided they are both passed the same parameter(s). The exact way in which your C functions are implemented does not have to match the assembly language code. In other words, if you run gcc on your own C code with -S and -O2, the assembly language produced from your code does not have to be an exact match with mine.
PROTOTYPE FOR FUNCTIONS:
#include <stdio.h>
#include <string.h>
#include "hw5.h"
TEMPLATES:
int f1(int a, int b, int c) {
return 0; // replace this
}
void f2(int *a, int b) {
}
int f3(long a) {
return 0; // replace this
}
int f4(int a, int b) {
return 0; // replace this
}
int f5(char *a) {
return 0; // replace this
}
char *f6(char *a, char *b) {
return a; // replace this
}
char *f7(char *a, char *b) {
return a; // replace this
}
void f8(int *a, int b) {
}
int f9(int *a, int b) {
return 0; // replace this
}
Explanation / Answer
here is your c code :
#include <stdio.h>
#include <string.h>
int f1(int a, int b, int c);
void f2(int *a, int b)
{
}
int f3(long a) {
return 0; // replace this
}
int f4(int a, int b) {
return 0; // replace this
}
int f5(char *a) {
return 0; // replace this
}
char *f6(char *a, char *b) {
return a; // replace this
}
char *f7(char *a, char *b) {
return a; // replace this
}
void f8(int *a, int b)
{
}
int f9(int *a, int b) {
return 0; // replace this
}
now im implementing my assembly assembly code please find the below code:
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.text
.align 2
.globl _Z2f2Pii
$LFB0 = .
.set nomips16
.ent _Z2f2Pii
.type _Z2f2Pii, @function
_Z2f2Pii:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI0:
sw $fp,4($sp)
$LCFI1:
move $fp,$sp
movz $31,$31,$0
$LCFI2:
sw $4,8($fp)
sw $5,12($fp)
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z2f2Pii
$LFE0:
.size _Z2f2Pii, .-_Z2f2Pii
.align 2
.globl _Z2f3l
$LFB1 = .
.set nomips16
.ent _Z2f3l
.type _Z2f3l, @function
_Z2f3l:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI3:
sw $fp,4($sp)
$LCFI4:
move $fp,$sp
movz $31,$31,$0
$LCFI5:
sw $4,8($fp)
move $2,$0
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z2f3l
$LFE1:
.size _Z2f3l, .-_Z2f3l
.align 2
.globl _Z2f4ii
$LFB2 = .
.set nomips16
.ent _Z2f4ii
.type _Z2f4ii, @function
_Z2f4ii:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI6:
sw $fp,4($sp)
$LCFI7:
move $fp,$sp
movz $31,$31,$0
$LCFI8:
sw $4,8($fp)
sw $5,12($fp)
move $2,$0
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z2f4ii
$LFE2:
.size _Z2f4ii, .-_Z2f4ii
.align 2
.globl _Z2f5Pc
$LFB3 = .
.set nomips16
.ent _Z2f5Pc
.type _Z2f5Pc, @function
_Z2f5Pc:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI9:
sw $fp,4($sp)
$LCFI10:
move $fp,$sp
movz $31,$31,$0
$LCFI11:
sw $4,8($fp)
move $2,$0
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z2f5Pc
$LFE3:
.size _Z2f5Pc, .-_Z2f5Pc
.align 2
.globl _Z2f6PcS_
$LFB4 = .
.set nomips16
.ent _Z2f6PcS_
.type _Z2f6PcS_, @function
_Z2f6PcS_:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI12:
sw $fp,4($sp)
$LCFI13:
move $fp,$sp
movz $31,$31,$0
$LCFI14:
sw $4,8($fp)
sw $5,12($fp)
lw $2,8($fp)
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z2f6PcS_
$LFE4:
.size _Z2f6PcS_, .-_Z2f6PcS_
.align 2
.globl _Z2f7PcS_
$LFB5 = .
.set nomips16
.ent _Z2f7PcS_
.type _Z2f7PcS_, @function
_Z2f7PcS_:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI15:
sw $fp,4($sp)
$LCFI16:
move $fp,$sp
movz $31,$31,$0
$LCFI17:
sw $4,8($fp)
sw $5,12($fp)
lw $2,8($fp)
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z2f7PcS_
$LFE5:
.size _Z2f7PcS_, .-_Z2f7PcS_
.align 2
.globl _Z2f8Pii
$LFB6 = .
.set nomips16
.ent _Z2f8Pii
.type _Z2f8Pii, @function
_Z2f8Pii:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI18:
sw $fp,4($sp)
$LCFI19:
move $fp,$sp
movz $31,$31,$0
$LCFI20:
sw $4,8($fp)
sw $5,12($fp)
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z2f8Pii
$LFE6:
.size _Z2f8Pii, .-_Z2f8Pii
.align 2
.globl _Z2f9Pii
$LFB7 = .
.set nomips16
.ent _Z2f9Pii
.type _Z2f9Pii, @function
_Z2f9Pii:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI21:
sw $fp,4($sp)
$LCFI22:
move $fp,$sp
movz $31,$31,$0
$LCFI23:
sw $4,8($fp)
sw $5,12($fp)
move $2,$0
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z2f9Pii
$LFE7:
.size _Z2f9Pii, .-_Z2f9Pii
.ident "GCC: (Debian 4.4.5-8) 4.4.5"