title: The values of operands in TEA algorithm will not get decrypted correctly in Assembly
body: <p>I'm writing an assembly project to perform Tiny Encryption algorithm. I followed <a href="https://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm" rel="nofollow noreferrer">the C-Code on Wikipedia</a> and transformed it into x86 assembly.</p>
  
  <p>However when I run the algorithm the inputs v0 and v1, they get transformed into gibberish as they should, however, when I try to decrypt the ciphertext, I don't get the original back.</p>
  
  <p>Here is the encryption procedure</p>
  
  <pre><code>encrypt PROC
  xor eax, eax
  xor ebx, ebx
  xor ecx, ecx
  xor edx, edx
  xor esi, esi
  xor edi, edi
  mov ecx, 32
  LOOP1:
  ;sum+= delta
  mov eax, sum
  ADD eax, delta
  mov sum, eax
  ; (v1 &lt;&lt; 4) + k0
  mov eax, v1
  SAL eax, 4
  ADD eax, key0
  mov v1l4, eax 
  ; (v1 + sum)
  mov eax, v1
  ADD eax, sum
  mov v1ps, eax
  ; (v1 &gt;&gt; 5) + k1
  mov eax, v1
  SHR eax, 5
  add eax, key1
  mov v1r5, eax
  ;((v1 &lt;&lt; 4) + k0) ^ (v1 + sum) ^ ((v1 &gt;&gt; 5) + k1)
  mov eax, v1l4
  xor eax, v1ps
  xor eax, v1r5
  ; v0 += ((v1 &lt;&lt; 4) + k0) ^ (v1 + sum) ^ ((v1 &gt;&gt; 5) + k1)
  ADD v0, eax
  ; (v0 &lt;&lt; 4) + k2
  mov eax, v0
  SAL eax, 4
  ADD eax, key2
  mov v0l4, eax 
  ; (v0 + sum)
  mov eax, v0
  ADD eax, sum
  mov v0ps, eax
  ; (v0 &gt;&gt; 5) + k3
  mov eax, v0
  SHR eax, 5
  add eax, key3
  mov v0r5, eax
  ; ((v0 &lt;&lt; 4) + k2) ^ (v0 + sum) ^ ((v0 &gt;&gt; 5) + k3)
  mov eax, v0l4
  xor eax, v0ps
  xor eax, v1r5
  ; v1 += ((v0 &lt;&lt; 4) + k2) ^ (v0 + sum) ^ ((v0 &gt;&gt; 5) + k3)
  ADD v1, eax
  
  dec ecx
  cmp ecx, 0
  JG LOOP1
  ret
  encrypt ENDP
  </code></pre>
  
  <p>Here is the decryption procedure</p>
  
  <pre><code>decrypt PROC
  xor eax, eax
  xor ebx, ebx
  xor ecx, ecx
  xor edx, edx
  xor esi, esi
  xor edi, edi
  mov ecx, 32
  LOOP2:
  ; (v0 &lt;&lt; 4) + k2
  mov eax, v0
  SAL eax, 4
  ADD eax, key2
  mov v0l4, eax 
  ; (v0 + sum)
  mov eax, v0
  ADD eax, sum
  mov v0ps, eax
  ; (v0 &gt;&gt; 5) + k3
  mov eax, v0
  SHR eax, 5
  ADD eax, key3
  mov v0r5, eax
  ; ((v0 &lt;&lt; 4) + k2) ^ (v0 + sum) ^ ((v0 &gt;&gt; 5) + k3)
  mov eax, v0l4
  xor eax, v0ps
  xor eax, v1r5
  ; v1 -= ((v0 &lt;&lt; 4) + k2) ^ (v0 + sum) ^ ((v0 &gt;&gt; 5) + k3)
  SUB v1, eax
  
  ; (v1 &lt;&lt; 4) + k0
  mov eax, v1
  SAL eax, 4
  ADD eax, key0
  mov v1l4, eax 
  ; (v1 + sum)
  mov eax, v1
  ADD eax, sum
  mov v1ps, eax
  ; (v1 &gt;&gt; 5) + k1
  mov eax, v1
  SHR eax, 5
  ADD eax, key1
  mov v1r5, eax
  ; ((v1 &lt;&lt; 4) + k0) ^ (v1 + sum) ^ ((v1 &gt;&gt; 5) + k1)
  mov eax, v1l4
  xor eax, v1ps
  xor eax, v1r5
  ; v0 -= ((v1 &lt;&lt; 4) + k0) ^ (v1 + sum) ^ ((v1 &gt;&gt; 5) + k1)
  SUB v0, eax
  ; sum -= delta
  mov eax, sum
  SUB eax, delta
  mov sum, eax
  
  dec ecx
  cmp ecx, 0
  JG LOOP2
  ret
  decrypt ENDP
  </code></pre>
  
  <p>Many thanks!</p>