title: Basic assembly calculator
body: <p>Please help me with this program! I have spent a lot of time on reading documents, but I don'y quite understand why my codes don't work. It's just a basic calculator and this is what I have so far. After the second method, none of them works. Thank you!</p>
  
  <pre><code>int calc (int op1, int op2, int opcode)
  {
  __asm
  {
  mov eax, 0       ; zero out the result
  mov ebx, opcode  ; move opcode to ebx for comparison
  cmp ebx, 0x01    ; check for ADD
  jne sub_2        ; jump if not 2 to sub
  mov eax, op1     ; move op1 into eax
  add eax, op2     ; add op2 into eax
  jmp done         ;    jump to done
  sub_2:
  cmp ebx, 0x02    ;
  jne mul_3        ;jump if not 3 to mul
  mov eax, op1     ;move op1 into eax
  sub eax, op2     ;subtract op2 into eax
  jmp done         ; jump to done
  mul_3:
  cmp ebx, 0x03    ;
  jne div_4        ; jump to div_4 if ot 3
  mov eax, 0       ; move 0 into eax
  mov ecx, op1     ; move op1 into ecx  
  mov edx, op2     ; move op2 into edx    
  L2:   
  //and ecx, 01    ; I'm not sure if I should do this to check the lowest bit
  jnc no_add       ; check if lowest bit is 0, if yes jump to no_add    
  add eax, edx     ; add edx to the result which is eax   
  no_add:    
  rcr ecx, 1       ; rotate with carry to right 1 bit ecx   
  shl edx, 1       ; shift left edx 1 bit  
  jnz L2           ; jump back to loop if edx is not 0   
  jmp done
  
  done:
  </code></pre>
  
  <p>}</p>