Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         push esi;
  2.         push edi;
  3.         push eax;
  4.         push ebx;
  5.         push ecx;
  6.         push edx;
  7.        
  8.         // START CODING HERE   
  9.         mov esi, 0; // currNum1
  10.         mov edi, 0; //currNum2
  11.         mov edx, 0; // currNum3
  12.         mov ecx, 0; //carry = 0
  13. WhileLoop:
  14.         cmp posNum3, 0;
  15.         JL WhileFalse;
  16. mov esi, 0; // currNum1 = currNum2 = 0
  17. mov edi, 0;
  18.  
  19. cmp posNum1, 0; // if posNum1 > 0;
  20. Jg if1;
  21. jmp skip;
  22.  
  23. if1:
  24. sub posNum1, 1; // posNum1--
  25. mov ebx, posNum1; // ebx = posnum1
  26. mov   eax, num1 ;// eax points to the beggining of the char array
  27. movsx eax, [eax + ebx] ;// ebx is the index
  28. mov esi, eax; // currnum1 = num1[posNum1]
  29. sub esi, '0'; // currnum1 = currnum1 - '0'
  30.  
  31. skip:
  32.  
  33. cmp posNum2, 0; // if posNum1 > 0;
  34. Jg if2;
  35. jmp skip2;
  36.  
  37. if2: // like if 1, no comments here, if if1 is messed up if2 will be
  38. sub posNum2, 1;
  39. mov ebx, posNum2;
  40. mov eax, num2 ;// eax points to the beggining of the string
  41. movsx eax, [eax + ebx] ;// ebx is the index
  42. mov edi, eax;
  43. sub edi, '0';
  44.  
  45. skip2:
  46.  
  47. mov edx, esi; // currNum3 = currNum1 + currNum2 + carry;
  48. add edx, edi;
  49. add edx, ecx;
  50.  
  51. mov ecx, 0; // carry = 0
  52.  
  53. cmp edx, 10; // if currNum3 >= 10
  54. jge if3;
  55. jmp skip3;
  56.  
  57. if3:
  58. sub edx, 10; // currNum3 = currNum3 - 10
  59. mov ecx, 1; // carry = 1
  60.  
  61. skip3:
  62. sub posNum3, 1;
  63.  
  64. //resNum[posNum3] = currNum3 + '0';
  65. mov edx, posNum3
  66. mov esi, resNum
  67. add al, '0'
  68. mov byte ptr [edx+esi], al
  69.  
  70. jmp WhileLoop;
  71.  
  72. WhileFalse:
  73.  
  74.        
  75.  
  76.  
  77.  
  78.         // END CODING HERE
  79.  
  80.         pop edx;
  81.         pop ecx;
  82.         pop ebx;
  83.         pop eax;
  84.         pop edi;
  85.         pop esi;
  86.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement