Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Suma numerelor intr-un vector char.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6.  
  7. int main()
  8. {
  9.     char s[20] = "+5 -3 +32 ";
  10.     int i, sum, nr, semn;
  11.     _asm
  12.     {
  13.         mov ebx, 0 // nr=0;
  14.         push 0 // sum //esp+4
  15.         push 0 //semn // esp
  16.         lea esi, s
  17.         startwhile:
  18.             mov ecx, [esi]
  19.             cmp ecx, '\0'
  20.             je stopwhile
  21.                 cmp ecx, '+'
  22.                 je Plus
  23.                 cmp ecx, '-'
  24.                 je Minus
  25.                 cmp ecx, ' '
  26.                 jne Others
  27.                 Plus:
  28.                     mov [esp], 0
  29.                     mov ebx, 0
  30.                     jmp IfSpace
  31.                 Minus:
  32.                     mov [esp], 1
  33.                     mov ebx, 0
  34.                     jmp IfSpace
  35.                 Others:
  36.                     sub [esi], '0'
  37.                     add ebx, [esi]
  38.                     add esi, 1
  39.                     cmp [esi], '\0'
  40.                     jne DoubleCond
  41.  
  42.                         DoubleCond:
  43.                             cmp [esi], ' '
  44.                             je IfSpace
  45.                             mov edx, 0
  46.                             mov eax, ebx
  47.                             mov ebx, 10
  48.                             mul ebx
  49.                             mov ebx, eax
  50.             add esi, 1
  51.  
  52.             IfSpace:
  53.                 cmp [esp], 0
  54.                 je Diff
  55.                 add [esp+4], ebx
  56.                     Diff:
  57.                         sub [esp+4], ebx
  58.  
  59.             jmp startwhile 
  60.  
  61.             stopwhile:
  62.                 mov eax, [esp+4]
  63.                 mov sum, eax
  64.                 add esp, 8
  65.  
  66.            
  67.     }
  68.     std::cout << sum;
  69.     /*while (s[i] != '\0')
  70.     {
  71.         if (s[i] == '+')
  72.         {
  73.             semn = 0;
  74.             nr = 0;
  75.         }
  76.         else
  77.         {
  78.             if (s[i] == '-')
  79.             {
  80.                 semn = 1;
  81.                 nr = 0;
  82.             }
  83.             else
  84.             {
  85.                 if (s[i] != ' ')
  86.                 {
  87.                     nr += s[i] - '0';
  88.                     if (s[i + 1] != ' ' && s[i+1]!= '\0')
  89.                         nr *= 10;
  90.                 }
  91.             }
  92.         }
  93.         if (s[i] == ' ')
  94.         {
  95.             std::cout << nr << '\n';
  96.             if (semn == 0)
  97.                 sum += nr;
  98.             else
  99.                 sum -= nr;
  100.         }
  101.         i++;
  102.     }
  103.     std::cout << sum;*/
  104. }
  105.  
  106. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  107. // Debug program: F5 or Debug > Start Debugging menu
  108.  
  109. // Tips for Getting Started:
  110. //   1. Use the Solution Explorer window to add/manage files
  111. //   2. Use the Team Explorer window to connect to source control
  112. //   3. Use the Output window to see build output and other messages
  113. //   4. Use the Error List window to view errors
  114. //   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
  115. //   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement