Sunday, April 11, 2021

Conditional Structures

Example 1 - Simple conditional

Pseudocode:


if( op1 == op2 )
{
  X = 1; 
  Y = 2;
} 


Assembly code:


  mov eax,op1
  cmp eax,op2
  jne L1
  mov X,1
  mov Y,2 
L1:
  ...


Example 2 - NTFS

Pseudocode:


    clusterSize = 8192;
    if terrabytes < 16
      clusterSize = 4096;


Assembly code:


  mov clusterSize,8192 
  cmp terrabytes, 16
  jae next
  mov clusterSize,4096 
next:
  ...


Example 3 - If Else

Pseudocode:


if op1 > op2
  call Routine1
else
  call Routine2
end if 


Assembly code:


  mov  eax,op1
  cmp  eax,op2
  jg   A1
  call Routine2
  jmp  A2
A1:
  call Routine1
A2:
  ...


Example 4 - nested If Else

Pseudocode:


if op1 == op2
  if X > Y
    call Routine1
  else
    call Routine2
  end if
else
  call Routine3
end if 


Assembly code:


  mov eax,op1 
  cmp eax,op2
  jne L2
  call Routine3
  mov eax,X
  cmp eax,Y
  jg L1
  call Routine2
  jmp L3 
L1:
  call Routine1
  jmp L3
L2:
  call Routine3 
L3:
  ...

No comments:

Post a Comment