title: Two's complement stored in EBX using ONLY ADD, MOV and SUB
body: <p>I need need to store the two’s complement of var1, var2, var3, and
  var4 in register ebx. The two’s complement of var1 is in the highest byte of ebx,
  the two’s complement of var2 is the next byte, the two’s complement of var3 is
  in the next byte, and the two’s complement of var4 is in the lowest byte.
  Remember that for a hexadecimal number, there are two steps to get the two’s
  complement:</p>
  <ol>
  <li>subtract the number from 15</li>
  <li>Add 1</li>
  </ol>
  <p>For example, the ‘D’ (44h) is stored in the highest byte of eax, so the
  two’s complement of 44h will be stored in the highest byte of ebx. The
  two’s complement of 44h is:</p>
  <ol>
  <li><p>15 – 4 = B (11) and
  15 – 4 = B (11)
  So we get BBh after step 1</p>
  </li>
  <li><p>BB + 1 = BC
  So the two’s complement of 44h is BCh, and this is what should end up in
  the highest byte of ebx</p>
  </li>
  </ol>
  <p>HINT: Think about how the sub instruction could be used to get the two’s
  complement of a number.
  NOTE: You should use the same shifting algorithm that you used for phase
  2 here. Start by placing the two’s complement of var1 and var2 into the
  lower
  16 bits of ebx, and then shift them into the upper 16 bits of ebx. Once that is
  completed, directly move the two’s complement of var3 and var4 to the
  lower 16 bits of ebx.
  After phase 3 is completed, register ebx should look like this:
  BCBFBEBD</p>
  <p>Here is the code I have so far, which was shifting around the values of the variables and story the values into EAX</p>
  <pre><code>.386
  .model flat,stdcall
  .stack 4096
  ExitProcess proto,dwExitCode:dword
  
  ; defining variables 
  .data
      var1 BYTE 'A'
      var2 BYTE 'B'
      var3 BYTE 'C'
      var4 BYTE 'D'
      
  .code
  main proc
      
      mov ah, var1
      mov al, var4
      mov bh, var2
      mov bl, var3
      mov var1, al
      mov var2, ah
      mov var3, bh
      mov var4, bl
      
      ;move var1 into ah
      ;move var2 into al
      ;add eax to eax 16 times to rotate var1 and var2 into the highest bytes
      mov ah, var1
      mov al, var2
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
      add eax, eax
  
      ;move var3 and var4 into the lowest byte postions 
      mov ah, var3
      mov al, var4
  
      invoke ExitProcess,0
  main endp
  end main
  </code></pre>