assume that x and p are declared as local variables and that appropriate allocation of pointers has been done Consider, first, the sizes of the data types involved Integer variable has size 2 bytes Character variable has size l bytes; The pointer has size 2 bytes The code generated for the statement X.=X1 IS mov ax, word ptr [bp-6 mov word ptr [bp-3,ax note Local variables are allocated only on even-byte boundaries The offset computation for j(-6+3=-3)is performed statically by the compiler
• Assume that X and P are declared as local variables and that appropriate allocation of pointers has been done. • Consider, first, the sizes of the data types involved. Integer variable has size 2 bytes; Character variable has size 1 bytes; The pointer has size 2 bytes. • The code generated for the statement x.j =x.i; is mov ax, word ptr [bp-6] mov word ptr [bp-3],ax • Notes: – Local variables are allocated only on even-byte boundaries; – The offset computation for j (-6 + 3 = -3 ) is performed statically by the compiler
The code generated for the statement p->lchild=p mov word ptr [si+2 si And the statement p= p->rchild; S mov si, word ptr [si+4
• The code generated for the statement p->lchild = p; is mov word ptr [si+2], si • And the statement p = p->rchild; is mov si, word ptr [si+4]
3)If and while-Statement The statements we use are if(x>y)y++; else x-i ane while(x<y y-=x: The borland compiler generates the following 80x86 code for the given if-statement cmp bx, dx jle short @l@86 inc dx mp short al@a114 alas dec bx a1@a114
3) If and While-Statement • The statements we use are if (x>y) y++; else x--; and while (x<y) y -= x; • The Borland compiler generates the following 80x86 code for the given if-statement: cmp bx , dx jle short @1@86 inc dx jmp short @1@114 @1@86 : dec bx @1@114 :
For the given while-statement Jmp short @1@170 a1a142 sub dx. bx a1a170 cmp bx, dx I short(@142
• For the given while-statement: jmp short @1@170 @1@142 : sub dx , bx @1@170 : cmp bx , dx jl short @1@142
4) Function definition and call The examples are the c function definition int f( int x, int y) return x+y+l; And a corresponding call f(2+3,4)
4) Function definition and call • The examples are the C function definition: int f( int x, int y) { return x+y+1 ; } • And a corresponding call f (2+3, 4)