Using x86 Assembly  Examples:
Assume the following values are stored in the indicated memory addresses and registers:

Address 	Value	         Register            Value	
0x100	0xFF	         %eax                                                  0x100	
0x104	0xAB	         %ecx                                                     0x1	
0x108	0x13	         %edx                                                      0x3	
0x10C	0x11		

Fill-in the following:
Operand                          Value
 %eax
 (0x104)
 $0x108
 (%eax)
 4(%eax)
 9(%eax, %edx)
 260(%ecx, %edx)
 0xFC(,%ecx,4)
 (%eax, %edx,4)

We have seen the MOV operation now, we look at a variant LEA (load effective address) LEA, the only instruction that performs 
memory addressing calculations but doesn't actually address memory. LEA accepts a standard memory addressing operand, 
but does nothing more than store the calculated memory offset in the specified register, which may be any general purpose register. Used to create pointers.
Ex.   eax contains x; ecx contains y
lea 6(%eax), %edx		
lea  (%eax, %ecx ), %edx		
lea  (%eax, %ecx, 4), %edx		
lea 7(%eax, %ecx, 8), %edx		
lea  0xA( , %ecx, 4), %edx		

The standard arthmetic operations: 
Ex The first two columns are memory locations and values involved in the instruction, the next two are registers and the values involved. Show the effect of each instruction and the location affected.
Addr	Value	Reg 	Value	Instruction	Dest & Value	
0x100	0xFF	eax	0x100	addl %ecx, (%eax)		
0x104	0xAB	ecx	0x1	subl %edx, 4(%eax) 		
0x108	0x13	edx	0x3	imull $16, (%eax, %edx,4)		
0x10C	0x11			incl 8(%eax)		
				subl %edx, %eax		

Assume x @ ebp+8;  y @ ebp+12;   z @ ebp +16 for ALL the examples below,
which show the assembled o/p from gcc. Show the original C function.
Ex1  (Note: SAR - shift right arithmetic; SHR - shift right logical)
movl 16(%ebp), %eax
leal    (%eax,  %eax, 2),  %eax,
sall    $4, %eax
movl  12(%ebp), %edx
addl    8(%ebp), edx
andl   0xFFFF, %edx
imull  %edx, %eax

Ex2 
movl  12(%ebp), %eax
xorl       8(%ebp), %eax
sarl      $3,   %eax 
notl     %eax
subl    16(% ebp), %eax

CONTROL:
Condition Codes (CC):  These are flags set by the most recent arith/logic instr.
and by two sp. operations CMP X, Y  (based on Y-X) and TEST X, Y (on X&Y).
CF - Carry Flag (Carry out of MSB); ZF - Zero Fl. (resulty of op.) SF - Sign (-ve result); OF - Overflow (+ve or -ve)

Jumps:   These jump depending in the CC's set. 
jmp <label>               1               direct
jmp *Operand           1               indirect
je / jz                       ZF = 1           
jne / jnz                ~ZF
js                             SF =1
jns                          ~SF 
jg                                                        >
jge                                                     >=
jl                                                        <
jle                                                      <=

Ex  Write a function in x86 assembly to return larger of x and y in EDX

Ex  (On Own) Write a function assembly to return smallest of x, y and z in EDX

Ex Assemble the following: 
  (i)      int abdiff ( int x, int y){
              if ( x < y )
                  return y - x;
              else
                   return x - y;}

(ii)     int fact_while( int n){                     (assume: n @ %ebp + 8
             int result = 1;
             while ( n > 1){
                 result *= n;
                 n--;}
              return result;}
    
(iii) Write (ii) above with a for

Ex. Given the assembly o/p from gcc- fill-in the blanks: (usual assumptions)
int aTest (int x, int y){
     int val =     ___         ;    
     if (                            ) {
          if(                       )
              val =   ___         ;                         
          else
              val =                    ;
     }else if (                  )
              val =                   ;
     return val;}
             	      mov  8(%ebp), %eax           // x in eax
      mov   12(%ebp), %edx      //  y in edx 
      cmp   $-3, %eax                //        
      jge   .L2                             // 
      cmp  %edx , %eax            // 
      jle      .L3
      imul   %edx, %eax              // 
      jmp  .L4                            //   
.L3:                                         // 
      lea    (%edx , %eax), %eax   // 
      jmp .L4
.L2:                                       // 
      cmp $2,  %eax              // 
      jg       .L5                      //  
      xor   %edx , %eax
      jmp    .L4
.L5:
       sub   %edx , %eax   //  
.L4: