0% found this document useful (0 votes)
25 views6 pages

Rema Lab 2 Mihirpatel k042

Uploaded by

Mihir Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views6 pages

Rema Lab 2 Mihirpatel k042

Uploaded by

Mihir Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Mihir Patel K042

Experiment No. 2
Aim: Study of operating system and assembly concepts
Title: 8086 Assembler
Part A:

Reverse Engineering has many uses in the field of cybersecurity, for example, many of us use
Cracks to use programs without buying them, but have you ever asked yourself how Cracks
works? Cracks are manufactured after the program that we will do the crack for is analysed,
so it analyses all the steps of the program to know where the protection code for the program
comes from. And after the whole program is analysed, the programmer’s role comes to create
Anti-License Software and be in the form of Cracks or Keygen. This is an example of the uses
of Reverse Engineering, but it is not the only use. There are many other uses such as security
auditing and product analysis and in the case of the loss of software documents, and also many
companies use Reverse Engineering to analyse competing products for them to know their
weaknesses and strengths for the competitive technical intelligence, and also use Reverse
Engineering to be a continuous development of companies’ software by analysing from a
reverse point of view Software Improvement.

One of the programming languages that are used in Reverse Engineering is Assembly
Language, which is one of the most important programming languages in this field and in
many other fields! It is the easy-to-read form for humans of machine language that forms
commands and is executed from a computer with a specific core. As for machine language, it
is a sequence of bits that represent computer commands.

Reverse Engineering sections:


Reverse Engineering is divided into many sections, and we will get to know some of them:
The Reverse Code Engineering
RCE is a branch of software engineering in which a set of techniques and tools are used to
arrive at a scheme or model of the program to understand the composition of the program to
make it easier for programmers to maintain the program and break the protection or take
some code to use in other programs, and all of these things can be used for useful things and
negative things because reverse engineering is a double-edged sword.

• Disassembler
We mean by converting the program from Machine Language to Assembly Language
to analyse the program.
• The Decompiler
The goal is to convert the program code to any other language such as C or C++.
• The Packers or un-packers
It is used to decipher the confusion between the interfaces of the program by decoding
its files.
• The Hex Editing
The goal is to get the Binary Code for the program.
Part B:
1. Refer following article.
https://www.pelock.com/articles/when-and-how-to-use-an-assembler-assembly-
programming-basics

2. Write c code to convert into assembly level using http://www.ctoassembly.com/

3. Conclude with output screenshots.

CODE 1: SWAP FUNCTION

swap:
PUSH %BP
MOV %SP, %BP
@swap_body:
MOV 8(%BP), %0
MOV (%0), %0
SUB %SP, $4, %SP
MOV %0, -4(%BP)
MOV 12(%BP), %0
MOV (%0), %0
MOV 8(%BP), %1
MOV %0, (%1)
MOV 12(%BP), %0
MOV -4(%BP), (%0)
@swap_exit:
MOV %BP, %SP
POP %BP
RET
main:
PUSH %BP
MOV %SP, %BP
@main_body:
SUB %SP, $4, %SP
MOV $5, -4(%BP)
SUB %SP, $4, %SP
MOV $10, -8(%BP)
LEA -4(%BP), %0
LEA -8(%BP), %1
PUSH %1
PUSH %0
CALL swap
ADD %SP, $8, %SP
MOV $0, %13
JMP @main_exit
@main_exit:
MOV %BP, %SP
POP %BP
RET

Swap function
1. The function starts with saving the base pointer (%BP) onto the stack and moving the
stack pointer (%SP) to the base pointer, effectively setting up a stack frame.
2. Inside swap, the original content of the memory location at %BP + 8 is moved into %0.
3. Then, the content of the memory location pointed by %0 is moved into %0.
4. Space for a local variable is reserved on the stack by subtracting 4 from the stack pointer.
5. The value in %0 is stored at the location pointed to by -4(%BP), effectively swapping the
values.
6. Similar steps are repeated for the second memory location: original content is loaded, the
value is swapped, and the result is stored back.
7. Finally, the function ends by restoring the stack pointer and base pointer to their original
values and returning.

Main function
1. The function starts similarly with setting up a stack frame.
2. Space for two local variables is reserved on the stack, and values 5 and 10 are stored in
them.
3. Pointers to these variables are loaded into registers %0 and %1, respectively.
4. The pointers are pushed onto the stack (arguments for the swap function).
5. swap function is called.
6. After the function call, stack pointer is adjusted to remove the arguments pushed for the
function call.
7. Value 0 is moved into register %13.
8. The function ends with cleaning up the stack frame and returning.

PARITY AND CARRY FLAGS GENERATED


CODE 2: RECURSIVE FUNCTION

fact:
PUSH %BP
MOV %SP, %BP
@fact_body:
@if0:
CMP 8(%BP), $1
JGT @false0
@true0:
MOV $1, %13
JMP @fact_exit
JMP @exit0
@false0:
@exit0:
SUB 8(%BP), $1, %0
PUSH %0
CALL fact
ADD %SP, $4, %SP
MUL 8(%BP), %13, %0
MOV %0, %13
JMP @fact_exit
@fact_exit:
MOV %BP, %SP
POP %BP
RET
main:
PUSH %BP
MOV %SP, %BP
@main_body:
SUB %SP, $4, %SP
MOV $4, -4(%BP)
PUSH -4(%BP)
CALL fact
ADD %SP, $4, %SP
JMP @main_exit
@main_exit:
MOV %BP, %SP
POP %BP
RET
Fact function
1. The function starts with saving the base pointer (%BP) onto the stack and moving the
stack pointer (%SP) to the base pointer, effectively setting up a stack frame.
2. Inside fact, there's a label @if0 which checks if the input value (located at %BP + 8) is
equal to 1. If it is, it sets the result to 1 and jumps to @fact_exit. If not, it continues to the
next step.
3. It calculates the factorial of the input value recursively by calling itself (fact) with the
decremented value as an argument. The result of the recursive call is stored in %0.
4. After the recursive call, it multiplies %0 (the factorial of the decremented value) with the
original input value to get the factorial of the original input value. The result is stored in
%13.
5. Finally, it ends by restoring the stack pointer and base pointer to their original values and
returning.

Main function
1. Similar to the fact function, it starts by setting up a stack frame.
2. It stores the number 4 in the local variable located at -4(%BP).
3. It pushes the value of this local variable onto the stack (argument for the fact function).
4. It calls the fact function.
5. After the function call, it cleans up the stack frame and returns.

CODE 3: SIMPLE FUNCTION


main:
PUSH %BP
MOV %SP, %BP
@main_body:
SUB %SP, $4, %SP
MOV $1, -4(%BP)
ADD -4(%BP), $2, %0
MOV %0, -4(%BP)
MOV -4(%BP), %13
JMP @main_exit
@main_exit:
MOV %BP, %SP
POP %BP
RET

1. Function Setup: The function starts by saving the base pointer (%BP) onto the stack and
moving the stack pointer (%SP) to the base pointer, setting up a stack frame.
2. Body of main:
• It reserves space for a local variable on the stack by subtracting 4 from the stack
pointer (%SP).
• The value 1 is moved into the local variable located at -4(%BP).
• It adds 2 to the value stored at -4(%BP) and stores the result in register %0.
• The value stored in %0 is then moved back to -4(%BP).
• The value stored at -4(%BP) (which is now updated) is moved into register %13.
• It jumps to @main_exit.
3. Function Exit:
• It restores the stack pointer and base pointer to their original values.
• It pops the base pointer from the stack.
• It returns.

You might also like