Question: Description: In the context of computer system security, understanding how high - level code translates to assembly language is essential for identifying potential vulnerabilities and

Description:
In the context of computer system security, understanding how high-level code translates to assembly language is essential for identifying potential vulnerabilities and crafting effective exploits. Assembly language serves as the bridge between high-level programming constructs and machine-level instructions, providing insights into memory management, control flow, and execution behaviors that are critical for vulnerability analysis.
This assignment aims to provide hands-on experience in translating C code into assembly language to understand how high-level constructs are translated into low-level machine operations. This exercise is crucial for mastering vulnerability analysis and exploit development, as it helps you grasp the underlying mechanics of how software operates at the hardware level and how vulnerabilities can be exploited.
Environment:
For this assignment, you will need to use the Windows 7 virtual machine. Within this environment, you will write your assembly program using the Geany text editor and compile it using NASM (Netwide Assembler). All the necessary tools for developing and compiling your assembly code are already preinstalled and configured in the provided Windows 7 VMware image.
Task (10 pts)
Translate the following C program into assembly language. Ensure that proper stack frames are created for each function.
int seq(int n1, int n2, int n3, int n4)
{
int n5;
n5= n1+n2+n3+n4;
return n5;
}
int main()
{
int num1=1;
int num2=1;
int num3=2;
int num4=4;
int next;
printf("Calculating next number in the sequence %d %d %d %d ...
", num1, num2,num3, num4);
next = seq(num1,num2,num3,num4);
printf("Next number in the sequence is %d
", next);
return next;
}
Assignment Submission:
Submit your assembly code as an .asm file on the Canvas submission page. Ensure that your code is well-commented to facilitate easy understanding and review. Recall that in assembly language, comments begin with a semicolon (;). Use semicolons generously to annotate different sections of your code, making it clear and easy to follow.
The Code needs to Follow this format:
;int sum(int x, int y)
;{
; return (x+y);
;}
;
;int main()
;{
; int a =5;
; int a =7;
; int result;
;
; result = sum(a,b);
; printf("%d\r
", result);
;
; return 0;
;}
extern printf
section .text
main:
;create a stack frame
push ebp
mov ebp, esp
sub esp, 12 ; Allocate space for a, b and result in the stack
mov dword [ebp-4],5 ;This is quivalent to a=5
mov dword [ebp-8],7 ;This is quivalent to b=7
push dword [ebp-8] ;push b as y
push dword [ebp-4] ;push a as x
call sum
add esp, 8 ;clean up the parameters pushed to the stack
mov dword [ebp-12], eax ;This is quivalent to result = sum(a,b)
; Destroy the stack frame and return a value
mov eax, 0
leave
ret
sum:
;create a stack frame
push ebp
mov ebp, esp
mov dword eax, [ebp+8] ;This will load the value of x in eax
mov dword ebx, [ebp+12] ;This will load the value of y in ebx
add eax, ebx ; This will add the values in eax and ebx and store the result in eax
;Destroy the stack frame and return a value
mov eax, 0
leave
ret
section .data
string db "%d",13,10,0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!