SHARE
TWEET

Untitled




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- // Suma numerelor intr-un vector char.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include "pch.h"
- #include <iostream>
- int main()
- {
- char s[20] = "+5 -3 +32 ";
- int i, sum, nr, semn;
- _asm
- {
- mov ebx, 0 // nr=0;
- push 0 // sum //esp+4
- push 0 //semn // esp
- lea esi, s
- startwhile:
- mov ecx, [esi]
- cmp ecx, '\0'
- je stopwhile
- cmp ecx, '+'
- je Plus
- cmp ecx, '-'
- je Minus
- cmp ecx, ' '
- jne Others
- Plus:
- mov [esp], 0
- mov ebx, 0
- jmp IfSpace
- Minus:
- mov [esp], 1
- mov ebx, 0
- jmp IfSpace
- Others:
- sub [esi], '0'
- add ebx, [esi]
- add esi, 1
- cmp [esi], '\0'
- jne DoubleCond
- DoubleCond:
- cmp [esi], ' '
- je IfSpace
- mov edx, 0
- mov eax, ebx
- mov ebx, 10
- mul ebx
- mov ebx, eax
- add esi, 1
- IfSpace:
- cmp [esp], 0
- je Diff
- add [esp+4], ebx
- Diff:
- sub [esp+4], ebx
- jmp startwhile
- stopwhile:
- mov eax, [esp+4]
- mov sum, eax
- add esp, 8
- }
- std::cout << sum;
- /*while (s[i] != '\0')
- {
- if (s[i] == '+')
- {
- semn = 0;
- nr = 0;
- }
- else
- {
- if (s[i] == '-')
- {
- semn = 1;
- nr = 0;
- }
- else
- {
- if (s[i] != ' ')
- {
- nr += s[i] - '0';
- if (s[i + 1] != ' ' && s[i+1]!= '\0')
- nr *= 10;
- }
- }
- }
- if (s[i] == ' ')
- {
- std::cout << nr << '\n';
- if (semn == 0)
- sum += nr;
- else
- sum -= nr;
- }
- i++;
- }
- std::cout << sum;*/
- }
- // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
- // Debug program: F5 or Debug > Start Debugging menu
- // Tips for Getting Started:
- // 1. Use the Solution Explorer window to add/manage files
- // 2. Use the Team Explorer window to connect to source control
- // 3. Use the Output window to see build output and other messages
- // 4. Use the Error List window to view errors
- // 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
- // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.