I got x86 code for addition of two numbers having comp3 type(see cobol) , logic of addition is quite strange and confusing but gives correct result .can anybody help me with this code
>>00401229<< add eax,33333333h ; [00 00 01 23] + [33 33 33 33] = [33 33 34 56]eax
0040122E add edx,33333333h ; [00 00 02 20] + [33 33 33 33] = [33 33 35 53]edx
00401234 mov ebx,eax ; copying eax to ebx ; ebx = eax = 33 33 34 56
00401236 xor ebx,edx ; [33 33 34 56] xor [33 33 35 53] = [00 00 01 05](EBX)
00401238 add eax,edx ; [33 33 34 56]eax + [33 33 35 53]edx = [66 66 69 A9]eax
0040123A xor ebx,eax ; [00 00 01 05](ebx) xor [66 66 69 A9](eax) = [66 66 68 AC](ebx)
0040123C shr ebx,3 ; 3 >> [66 66 68 AC](ebx) = [0C CC CD 15](ebx)
0040123F not ebx ; [0C CC CD 15](ebx) NOT ==> [F3 33 32 EA](ebx)
00401241 and ebx,22222222h ; [F3 33 32 EA](ebx) & [22 22 22 22] = [22 22 22 22]
00401247 lea ebx,[ebx+ebx*2] ;ebx = 66 66 66 66
0040124A sub eax,ebx ;[66 66 69 A9]eax - [66 66 66 66]ebx = 343
more code may not be relevant
004011D1 mov eax,3C120000h // EAX = 3C120000h
004011D6 mov dword ptr [$HELLO.DATA+0D8h (409A08h)],eax // at 409A08h moving data 00 00 12 3c
004011DB mov eax,0C220000h // EAX = 0C220000h
004011E0 mov dword ptr [$HELLO.DATA+0E0h (409A10h)],eax // at 409A10h moving data 00 00 22 0c
004011E5 sub eax,eax // may be clearing eax
004011E7 mov eax,dword ptr [$HELLO.DATA+0D8h (409A08h)] // copying from 409A08h data(00 00 12 3c) to EAX
004011EC bswap eax // eax becomes 00 00 12 3c from 3C 12 00 00h
004011EE sub edx,edx // perhaps clearing edx
004011F0 mov edx,dword ptr [$HELLO.DATA+0E0h (409A10h)] // copying from 409A08h data 00 00 22 0c to EDX
004011F6 bswap edx // edx becomes 00 00 22 0c from 0C 22 00 00
004011F8 mov ebx,eax ....................................// copying from eax to ebx , ebx becomes 00 00 12 3c
004011FA and ebx,0Fh ....................................// ebx & 0Fh,(00 00 12 3c)&(0Fh) => 00 00 00 0C
// extracting sign from value ebx ,storing 'C' in ebx
004011FD mov ch,byte ptr $HELLO.LIT+230h (40E230h)[ebx] // 'ch' refer to 8 to 15 bits of ecx register
// ecx register -> |_15 to 8_| 7 to 0| ,
// byte from ebx is copied to ecx position 8 to 15
00401203 mov ebx,edx // value of edx ( 00 00 22 0C ) copied to ebx
00401205 and ebx,0Fh // extracting sign of second no by preserving last
nibble , now ebx has sign of second no i.e 'C'
00401208 mov cl,byte ptr $HELLO.LIT+230h (40E230h)[ebx] // 'CL' refer to '0 TO 7th' bit of 'E C X'
// Copying last 7 bits of ebx to cl
// ECX Becomes ECX = 8E 19 '0C' '0C'
// contains sign of both var , var1 and var 2
15 to 8 and 7 to 0
0040120E shr eax,4 // shifitng EAX right , removing sign nibble from var1
00401211 shr edx,4 // shifitng EDX right , removing sign nibble from var2
var2 , EDX = 00000220
var1 , EAX = 00000123
00401214 cmp ch,cl // comparing the sign of both number
// Both ch & cl part of ECX
//CMP - If the two values are equal, the Z Flag is set (1) otherwise it is not set (0)
00401216 je $HELLO.CODE+219h (401229h) // if both sign equal jump to '401229h'
//JE and JZ : a conditional jump when ZF (the "zero" flag) is equal to 1.
// var2 , EDX = 00000220
// var1 , EAX = 00000123