{"id":324238,"date":"2021-06-02T21:00:52","date_gmt":"2021-06-02T21:00:52","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=324238"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=324238","title":{"rendered":"Benchmark CPU&#8217;s Instructions (just before loading the OS) \u2014 XCHG vs XOR, XOR, XOR"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8b5\/33e\/f09\/8b533ef095c8c6f2381ab2917f325588.jpg\" alt=\"1.225.000 - \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0434\u043b\u044f XCHG (\u0441\u043b\u0435\u0432\u0430), 1.280.014 - \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0434\u043b\u044f XOR, XOR, XOR (\u0441\u043f\u0440\u0430\u0432\u0430)\" title=\"1.225.000 - \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0434\u043b\u044f XCHG (\u0441\u043b\u0435\u0432\u0430), 1.280.014 - \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0434\u043b\u044f XOR, XOR, XOR (\u0441\u043f\u0440\u0430\u0432\u0430)\" width=\"960\" height=\"1280\"><figcaption>1.225.000 &#8212; \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0434\u043b\u044f XCHG (\u0441\u043b\u0435\u0432\u0430), 1.280.014 &#8212; \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0434\u043b\u044f XOR, XOR, XOR (\u0441\u043f\u0440\u0430\u0432\u0430)<\/figcaption><\/figure>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0430 \u043a\u0430\u043a\u043e\u0432 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u0434 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 XCHG \u043d\u0430 RISC \u0434\u043b\u044f x86 CISC?\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438 \u0434\u043b\u044f \u043a\u043e\u0433\u043e \u043d\u0435 \u0441\u0435\u043a\u0440\u0435\u0442, \u0447\u0442\u043e \u043d\u0430 \u044f\u0437\u044b\u043a\u0430\u0445 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 &#171;X&#187; \u0438 &#171;Y&#187;, \u043d\u0443\u0436\u043d\u0430 \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0441\u043a\u0430\u0436\u0435\u043c &#171;Z&#187;.<\/p>\n<p>X=5, Y=7<br \/>Z=Y<br \/>Y=X<br \/>X=Z<br \/>X=7, Y=5<\/p>\n<p>\u041d\u043e, \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u044b \u044d\u0442\u043e \u0443\u043c\u0435\u044e\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 XCHG, \u043f\u0440\u0438\u0447\u0451\u043c, \u044f\u0432\u043d\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0437\u0434\u0435\u0441\u044c \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u043a\u0430\u043a \u0438 \u043d\u0435\u0442&#8230;<\/p>\n<p>X=5, Y=7<br \/>XCHG X, Y<br \/>X=7, Y=5<\/p>\n<p>\u042f \u0434\u0430\u0436\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u043b \u0447\u0442\u043e \u0441\u0430\u043c\u0430 \u0430\u0431\u0431\u0440\u0435\u0432\u0438\u0430\u0442\u0443\u0440\u0430 &#171;XCHG&#187;, \u044d\u0442\u043e \u043d\u0438 \u0447\u0442\u043e \u0438\u043d\u043e\u0435 \u043a\u0430\u043a &#171;XOR CHANGE&#187;, \u0441\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0436\u0443 \u0447\u0442\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0434\u043e\u0433\u0430\u0434\u043a\u0438 \u044f \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b. \u041f\u043e\u0447\u0435\u043c\u0443 XOR CHANGE? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u0431\u043c\u0435\u043d \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u043c\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441 \u0443\u0447\u0430\u0441\u0442\u0438\u0435\u043c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b XOR.<\/p>\n<p>X=5, Y=7<br \/>XOR X, Y<br \/>XOR Y, X<br \/>XOR X, Y<br \/>X=7, Y=5<\/p>\n<p>\u0427\u0442\u043e \u0436, \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u0442\u0435\u043e\u0440\u0438\u044e, \u043f\u0440\u043e\u043c\u0435\u0440\u0438\u0432 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 &#171;XCHG&#187; \u0438 \u0435\u0451 \u0430\u043d\u0430\u043b\u043e\u0433\u0430 &#171;XOR, XOR, XOR&#187;. \u041d\u0443 \u0430 \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u044b\u043b\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438, \u044f \u0440\u0435\u0448\u0438\u043b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0451 \u044d\u0442\u043e \u0434\u0435\u043b\u043e \u0435\u0449\u0451 \u0434\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0442.\u0435. \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0411\u0418\u041e\u0421 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u0440\u0435\u0448\u0438\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f  \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u043a\u043e\u043f\u0438\u0442\u0435\u043b\u044f. \u0412 \u043e\u0431\u0449\u0435\u043c \u0434\u043b\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0438\u0441\u0442\u043e\u0442\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430, \u044f \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043b \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434 \u043f\u0440\u044f\u043c\u043e \u0432 MBR \u0437\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0433\u043e \u0434\u0438\u0441\u043a\u0430 (\u0432 \u0441\u0432\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0444\u043b\u0435\u0448\u043a\u0443).<br \/>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e &#171;XCHG EDI, EAX&#187; 7 \u0440\u0430\u0437, \u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e &#171;XOR&#187; &#8212; 21 \u0440\u0430\u0437 \u043d\u0443 \u0438 \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043a\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430. \u0426\u0438\u043a\u043b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u043e 10000 \u0440\u0430\u0437. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u0441\u0451 \u044d\u0442\u043e \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0435\u0449\u0451 \u0438 \u0435\u0449\u0451 (\u0432\u0441\u0435\u0433\u043e 20 \u0440\u0430\u0437), \u0432 \u0438\u0442\u043e\u0433\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0440\u0435\u0434\u043d\u0435\u0435. \u041a\u0430\u043a \u043f\u043e \u043c\u043d\u0435, \u0442\u0435\u0441\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e &#171;\u0447\u0438\u0441\u0442\u044b\u0439&#187;, \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439. \u041d\u0443 \u0430 \u0447\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u0433\u043e, \u0440\u0430\u0432\u043d\u044b \u043b\u0438 \u043f\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 XCHG \u0438 \u0442\u0440\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b XOR, \u0442\u043e \u0441\u0443\u0434\u044f \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0442\u0435\u0441\u0442\u0443, XCHG \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 5% \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0442\u043e \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u043e\u044e \u0442\u0435\u043e\u0440\u0438\u044e \ud83d\ude42 <\/p>\n<pre><code>\u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043d\u044b\u0445 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432 + \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u043e\u0432 \u043a\u043e\u0434\u0430              mov      ax, 3              int      10h              cli                            ; \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u043c \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f              mov      al, 0FFh              out      021h, al              out      0A1h, al              mov      cx, 20                ; \u0441\u0434\u0435\u043b\u0430\u0435\u043c 20 \u043f\u043e\u043f\u044b\u0442\u043e\u043a again:       push     cx              xor      ebp, ebp              mov      si, 10000             ; \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c 10000 \u0440\u0430\u0437 \u0434\u043b\u044f XCHG @@:          xor      eax, eax              xor      edi, edi              cpuid                          ; \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043c \u0426\u041f\u0423 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b              rdtsc rept 7     { xchg     edi, eax }            ; \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c 7 \u0440\u0430\u0437 XCHG              cpuid              rdtsc              sub      eax, edi\t            ; \u0432\u044b\u0447\u0442\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443              add      ebp, eax              ; \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b              dec      si              jnz      @B              mov      [_xchg], ebp                        xor      ebp, ebp              mov      si, 10000             ; \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c 10000 \u0440\u0430\u0437 \u0434\u043b\u044f XOR @@:          xor      eax, eax              xor      edi, edi              cpuid              rdtsc rept 7     { xor      edi, eax              ; \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c 7 \u0440\u0430\u0437 \u043f\u043e \u0442\u0440\u0438 XOR              xor      eax, edi              xor      edi, eax }              cpuid              rdtsc              sub      eax, edi              add      ebp, eax              dec      si              jnz      @B next:        mov      [_xor], ebp              mov      eax, [_xchg]              add      [totalxchg], eax              mov      di, [screen]              call     print              add      word [screen], 32              mov      eax, [_xor]              add      [totalxor], eax              mov      di, [screen]              call     print              add      word [screen], 128              pop      cx              dec      cx              jnz      again              dec      byte [color+1]              mov      eax, [totalxchg]              mov      ebx, 20              xor      edx, edx              idiv     ebx              mov      di,[screen]              call     print              mov      eax, [totalxor]              mov      ebx, 20              xor      edx, edx              idiv     ebx              add      word [screen], 32              mov      di,[screen]              call     print @@:          jmp      @B                ; \u043d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. print:       mov      ebx, 10           ; \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d              xor      cx, cx more:        mov      si, bufferdec+12              xor      edx, edx              sub      si, cx              idiv     ebx              add      dl, '0'              mov      [si], dl              inc      cx              test     cl, 1              je       @F              test     cl, 2              je       @F              or       eax, eax              je       @F              mov      [si-1], byte '.'              inc      cx @@:          or       eax, eax              jne      more color:       mov      ah, 7              push     0b800h              pop      es              mov      si, bufferdec+12              add      di, cx              add      di, cx              std @@:          lodsb              stosw              loop     @b              push     cs              pop      es              ret screen:      dw 0 _xchg:       dd 0 totalxchg:   dd 0 _xor:        dd 0 totalxor:    dd 0 bufferdec:   db 12 dup 0  rb 510 - ($ - $$) db 55h,0AAh  <\/code><\/pre>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/560690\/\"> https:\/\/habr.com\/ru\/post\/560690\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption>1.225.000 &#8212; \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0434\u043b\u044f XCHG (\u0441\u043b\u0435\u0432\u0430), 1.280.014 &#8212; \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0434\u043b\u044f XOR, XOR, XOR (\u0441\u043f\u0440\u0430\u0432\u0430)<\/figcaption><\/figure>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0430 \u043a\u0430\u043a\u043e\u0432 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u0434 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 XCHG \u043d\u0430 RISC \u0434\u043b\u044f x86 CISC?\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438 \u0434\u043b\u044f \u043a\u043e\u0433\u043e \u043d\u0435 \u0441\u0435\u043a\u0440\u0435\u0442, \u0447\u0442\u043e \u043d\u0430 \u044f\u0437\u044b\u043a\u0430\u0445 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 &#171;X&#187; \u0438 &#171;Y&#187;, \u043d\u0443\u0436\u043d\u0430 \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0441\u043a\u0430\u0436\u0435\u043c &#171;Z&#187;.<\/p>\n<p>X=5, Y=7<br \/>Z=Y<br \/>Y=X<br \/>X=Z<br \/>X=7, Y=5<\/p>\n<p>\u041d\u043e, \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u044b \u044d\u0442\u043e \u0443\u043c\u0435\u044e\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 XCHG, \u043f\u0440\u0438\u0447\u0451\u043c, \u044f\u0432\u043d\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0437\u0434\u0435\u0441\u044c \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u043a\u0430\u043a \u0438 \u043d\u0435\u0442&#8230;<\/p>\n<p>X=5, Y=7<br \/>XCHG X, Y<br \/>X=7, Y=5<\/p>\n<p>\u042f \u0434\u0430\u0436\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u043b \u0447\u0442\u043e \u0441\u0430\u043c\u0430 \u0430\u0431\u0431\u0440\u0435\u0432\u0438\u0430\u0442\u0443\u0440\u0430 &#171;XCHG&#187;, \u044d\u0442\u043e \u043d\u0438 \u0447\u0442\u043e \u0438\u043d\u043e\u0435 \u043a\u0430\u043a &#171;XOR CHANGE&#187;, \u0441\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0436\u0443 \u0447\u0442\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0434\u043e\u0433\u0430\u0434\u043a\u0438 \u044f \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b. \u041f\u043e\u0447\u0435\u043c\u0443 XOR CHANGE? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u0431\u043c\u0435\u043d \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u043c\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441 \u0443\u0447\u0430\u0441\u0442\u0438\u0435\u043c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b XOR.<\/p>\n<p>X=5, Y=7<br \/>XOR X, Y<br \/>XOR Y, X<br \/>XOR X, Y<br \/>X=7, Y=5<\/p>\n<p>\u0427\u0442\u043e \u0436, \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u0442\u0435\u043e\u0440\u0438\u044e, \u043f\u0440\u043e\u043c\u0435\u0440\u0438\u0432 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 &#171;XCHG&#187; \u0438 \u0435\u0451 \u0430\u043d\u0430\u043b\u043e\u0433\u0430 &#171;XOR, XOR, XOR&#187;. \u041d\u0443 \u0430 \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u044b\u043b\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438, \u044f \u0440\u0435\u0448\u0438\u043b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0451 \u044d\u0442\u043e \u0434\u0435\u043b\u043e \u0435\u0449\u0451 \u0434\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0442.\u0435. \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0411\u0418\u041e\u0421 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u0440\u0435\u0448\u0438\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f  \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u043a\u043e\u043f\u0438\u0442\u0435\u043b\u044f. \u0412 \u043e\u0431\u0449\u0435\u043c \u0434\u043b\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0438\u0441\u0442\u043e\u0442\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430, \u044f \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043b \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434 \u043f\u0440\u044f\u043c\u043e \u0432 MBR \u0437\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0433\u043e \u0434\u0438\u0441\u043a\u0430 (\u0432 \u0441\u0432\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0444\u043b\u0435\u0448\u043a\u0443).<br \/>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e &#171;XCHG EDI, EAX&#187; 7 \u0440\u0430\u0437, \u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e &#171;XOR&#187; &#8212; 21 \u0440\u0430\u0437 \u043d\u0443 \u0438 \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043a\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430. \u0426\u0438\u043a\u043b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u043e 10000 \u0440\u0430\u0437. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u0441\u0451 \u044d\u0442\u043e \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0435\u0449\u0451 \u0438 \u0435\u0449\u0451 (\u0432\u0441\u0435\u0433\u043e 20 \u0440\u0430\u0437), \u0432 \u0438\u0442\u043e\u0433\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0440\u0435\u0434\u043d\u0435\u0435. \u041a\u0430\u043a \u043f\u043e \u043c\u043d\u0435, \u0442\u0435\u0441\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e &#171;\u0447\u0438\u0441\u0442\u044b\u0439&#187;, \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439. \u041d\u0443 \u0430 \u0447\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u0433\u043e, \u0440\u0430\u0432\u043d\u044b \u043b\u0438 \u043f\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 XCHG \u0438 \u0442\u0440\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b XOR, \u0442\u043e \u0441\u0443\u0434\u044f \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0442\u0435\u0441\u0442\u0443, XCHG \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 5% \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0442\u043e \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u043e\u044e \u0442\u0435\u043e\u0440\u0438\u044e \ud83d\ude42 <\/p>\n<pre><code>\u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043d\u044b\u0445 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432 + \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u043e\u0432 \u043a\u043e\u0434\u0430              mov      ax, 3              int      10h              cli                            ; \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u043c \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f              mov      al, 0FFh              out      021h, al              out      0A1h, al              mov      cx, 20                ; \u0441\u0434\u0435\u043b\u0430\u0435\u043c 20 \u043f\u043e\u043f\u044b\u0442\u043e\u043a again:       push     cx              xor      ebp, ebp              mov      si, 10000             ; \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c 10000 \u0440\u0430\u0437 \u0434\u043b\u044f XCHG @@:          xor      eax, eax              xor      edi, edi              cpuid                          ; \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043c \u0426\u041f\u0423 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b              rdtsc rept 7     { xchg     edi, eax }            ; \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c 7 \u0440\u0430\u0437 XCHG              cpuid              rdtsc              sub      eax, edi\t            ; \u0432\u044b\u0447\u0442\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443              add      ebp, eax              ; \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b              dec      si              jnz      @B              mov      [_xchg], ebp                        xor      ebp, ebp              mov      si, 10000             ; \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c 10000 \u0440\u0430\u0437 \u0434\u043b\u044f XOR @@:          xor      eax, eax              xor      edi, edi              cpuid              rdtsc rept 7     { xor      edi, eax              ; \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c 7 \u0440\u0430\u0437 \u043f\u043e \u0442\u0440\u0438 XOR              xor      eax, edi              xor      edi, eax }              cpuid              rdtsc              sub      eax, edi              add      ebp, eax              dec      si              jnz      @B next:        mov      [_xor], ebp              mov      eax, [_xchg]              add      [totalxchg], eax              mov      di, [screen]              call     print              add      word [screen], 32              mov      eax, [_xor]              add      [totalxor], eax              mov      di, [screen]              call     print              add      word [screen], 128              pop      cx              dec      cx              jnz      again              dec      byte [color+1]              mov      eax, [totalxchg]              mov      ebx, 20              xor      edx, edx              idiv     ebx              mov      di,[screen]              call     print              mov      eax, [totalxor]              mov      ebx, 20              xor      edx, edx              idiv     ebx              add      word [screen], 32              mov      di,[screen]              call     print @@:          jmp      @B                ; \u043d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. print:       mov      ebx, 10           ; \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d              xor      cx, cx more:        mov      si, bufferdec+12              xor      edx, edx              sub      si, cx              idiv     ebx              add      dl, '0'              mov      [si], dl              inc      cx              test     cl, 1              je       @F              test     cl, 2              je       @F              or       eax, eax              je       @F              mov      [si-1], byte '.'              inc      cx @@:          or       eax, eax              jne      more color:       mov      ah, 7              push     0b800h              pop      es              mov      si, bufferdec+12              add      di, cx              add      di, cx              std @@:          lodsb              stosw              loop     @b              push     cs              pop      es              ret screen:      dw 0 _xchg:       dd 0 totalxchg:   dd 0 _xor:        dd 0 totalxor:    dd 0 bufferdec:   db 12 dup 0  rb 510 - ($ - $$) db 55h,0AAh  <\/code><\/pre>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/560690\/\"> https:\/\/habr.com\/ru\/post\/560690\/<\/a><br \/><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/br><\/p>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-324238","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=324238"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324238\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}