Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There are two seperate parts to the problem the first is giving the purpose to e

ID: 3761990 • Letter: T

Question

There are two seperate parts to the problem the first is giving the purpose to each piece of the disassembled code and then writing a C code for what bar ( ) would do. If you ned more information just ask/tell me what to do. Thanks!

I have a assembly code for bar here is the general structure of the function:

and the assembly code:

I need to fill this table with the purpose of each instruction (the why):

And then I need to write a C function that does what bar ( ) does. I can use my own parameters for var(s) and local var(s).

Explanation / Answer

1.

ebp is known as the base pointer or the frame pointer. On entry to your function, you push it (to save the value for the calling function). Then, you copy esp, the stack pointer, into ebp, so that ebp now points to your function's stack frame. At the end of your function, you then pop ebp so that the calling function's value is restored.

For some clarification on exactly what is going on - the push instruction puts the value from the specified register (ebp in this case), onto the stack, and decrements the stack pointer by the appropriate amount. The pop operation is the opposite - it increments the stack pointer and takes a value from the stack and puts it in the specified register

2.movl %esp, %ebp takes the current stack pointer and uses it as the frame for the called function

3.subl $16, %esp leaves room for local variables

http://stackoverflow.com/questions/4228261/understanding-the-purpose-of-some-assembly-statements

CODE:

#include<graphics.h>
#include<stdio.h>
#include<math.h>
#include<dos.h>
#include<conio.h>

void main()
{

int i,n,a,b;

void drawrect(int ,int);

int graphdriver = DETECT, graphmode;

initgraph(&graphdriver, &graphmode, "..\bgi");

setcolor(CYAN);

printf("ENTER THE NUMBER OF DATA ELEMENTS ");

scanf("%d",&n);

line(1,1,1,479);// Y axis

line(1,479,640,479);// X axis

for(i=1;i<=25;i++)
{

outtextxy(40*i,470,"|");
outtextxy(1,479-40*i,"-");

}

printf("ENTER X AND Y CO-ORDINATES ");

for(i=1;i<=n;i++)
{

scanf("%d %d",&a,&b);
b--;
drawrect(a*40,b*40);

}

getch();
closegraph();
}

void drawrect(int a,int b)
{
setfillstyle(SOLID_FILL,CYAN);
bar3d(a,478,a,430-b,5,1);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote