Please show all the steps and comments Use only basic 8086 i

Please, show all the steps and comments. Use only basic 8086 instruction set.

Convert the following C program to x86 assembly code.

----- C code -----

#define count 2

int y[2];

int main (void)

{

int A, B;

y[0] = A + B – count;

y[1] = - B + count;

return(0);

}

Solution

I use the gcc compiler tool chain to do this . You can generate the assembly code using it. YOu can do it if you have the gcc compiler installed on your system. Let\'s say the program file is \"pgm.c\"

STEP:1 Pre-compilation step

// The constants that you define using pre processor directives doesn\'t go into binary and is replaced in this phase.

cpp -o pgm.i pgm.c

STEP:2 Compilation step // Generate the assembly code

cc -o pgm.s -S pgm.i

You can check the assembly code in pgm.s file

STEP:3 Object code generation

as -o pgm.o pgm.s

Now you can also disassemble the object file using objdump

objdump -d pgm.o

Following is the output of the objdump utility for your program :

pgm.o: file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <main>:
0:   55    push %rbp
1:   48 89 e5    mov %rsp,%rbp
4:   8b 45 f8    mov -0x8(%rbp),%eax
7:   8b 55 fc    mov -0x4(%rbp),%edx
a:   01 d0     add %edx,%eax
c:   83 e8 02    sub $0x2,%eax
f:   89 05 00 00 00 00     mov %eax,0x0(%rip) # 15 <main+0x15>
15:   b8 02 00 00 00    mov $0x2,%eax
1a:   2b 45 f8    sub -0x8(%rbp),%eax
1d:   89 05 00 00 00 00     mov %eax,0x0(%rip) # 23 <main+0x23>
23:   b8 00 00 00 00    mov $0x0,%eax
28:   5d    pop %rbp
29:   c3    retq

Please, show all the steps and comments. Use only basic 8086 instruction set. Convert the following C program to x86 assembly code. ----- C code ----- #define c
Please, show all the steps and comments. Use only basic 8086 instruction set. Convert the following C program to x86 assembly code. ----- C code ----- #define c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site