• API
• FAQ
• Tools
• Archive
daily pastebin goal
60%
SHARE
TWEET

# Invers

a guest Jan 22nd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. // ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
2. //
3.
4. #include "pch.h"
5. #include <iostream>
6.
7. using namespace std;
8.
9. int invers(int);
10. int main()
11. {
12.     int n;
13.     cin >> n;
14.     cout << invers(n);
15. }
16.
17. int invers(int)
18. {
19.     /*
20.     Notatii:
21.      edi = nr
22.      esi = 10
23.      ebx = inv
24.
25.      ALGORITM:
26.      inv=0
27.      while nr!=0 do
28.         nr/10=c rest r => inv=inv*10+r nr=c
29.
30.      Cum facem impartirea:
31.      1.Facem edi/esi = eax rest edx ("edi/esi" adica "mov eax,edi" + "div esi")
32.      2.in ecx vom tine minte restul edx (edx e folosit by default la inmultire deci se sterge valoarea)
33.      rezultat=> inv=inv*10+ecx (inv=inv*10+nr%10) si edi(nr-ul)=eax ( nr=[nr/10])
34.      */
35.     _asm {
36.         mov edi,[ebp+8]
37.         mov esi,10
38.         mov ebx,0
39.
40.         forInceput:
41.         cmp edi,0
42.         je stopFor
43.
44.         mov eax,edi // mutam edi(nr-ul) in eax
45.         mov edx,0   // necesar ptr div
46.         div esi     // (edx::eax)/esi = eax rest edx  ( esi=10!!!)
47.         mov edi,eax // edi=[edi/10]
48.
49.         //restul este adaugat la inv
50.         mov ecx,edx // tinem minte restul in ecx
51.         mov eax,ebx // mutam inversul in eax
52.         mul esi     // eax*esi= edx::eax => edx=0 si eax=inv*10
53.         mov ebx,eax // inv = inv*10
54.         add ebx,ecx // inv = inv*10 + n%10
55.
56.         jmp forInceput
57.         stopFor:
58.         mov eax,ebx //eax returneaza deci salvam in el nr-ul
59.     }
60. }
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.

Top