Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PART A: We will look at C code versus machine code. Write the following code in cygwin using vi and save it as code.c. int

PART A:

We will look at C code versus machine code. Write the following code in cygwin using vi and save it

as code.c.

int main()

{

int i=1;

int j=1;

j=i+10;

j++;

return 0;

}

Compile the code with the following format.

$> gcc S code.c

This will create an assembly file code.s.

Use the cat command to view the contents of code.s.

The assembly code will look something like the following. The annotations will help explain what the

code does.

movl $1, -4(%rbp) //Move first variable onto stack (rbp is base pointer), set

value to 1

movl $1, -8(%rbp) //Move second variable onto stack, set value to 1

movl -4(%rbp), %eax //Move first variable to register %eax

addl $10, %eax //Add 10 to variable in register %eax

movl %eax, -8(%rbp) //Move the value in register %eax to the second variable

addl $1, -8(%rbp) //Add 1 to the second variable

movl $0, %eax //Set the value of register %eax to 0

addq $48, %rsp //Reset stack pointer

popq %rbp //Restore frame pointer

ret

Using the above as an example, write C code to yield the following assembly code. Note that %eax and

%edx are two different registers.

movl $0, -4(%rbp)

movl $0, -8(%rbp)

movl $0, -12(%rbp)

movl -8(%rbp), %eax

movl -4(%rbp), %edx

addl %edx, %eax

movl %eax, -12(%rbp)

movl $0, %eax

addq $48, %rsp

popq %rbp

ret

Write C code below.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions