-
Notifications
You must be signed in to change notification settings - Fork 20
/
0x10.asm
35 lines (30 loc) · 1010 Bytes
/
0x10.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;
; $Id: 0x10.asm,v 1.1.1.1 2016/03/27 08:40:12 raptor Exp $
;
; 0x10 explanation - from xchg rax,rax by [email protected]
; Copyright (c) 2016 Marco Ivaldi <[email protected]>
;
; This is the funniest snippet so far. It illustrates
; different ways to exchange the content of rax with rcx.
;
; This analysis was facilitated by the assembly REPL rappel
; by [email protected]:
;
; https://github.com/yrp604/rappel/
;
BITS 64
SECTION .text
global main
main:
push rax ; push the value of rax onto the stack
push rcx ; push the value of rcx onto the stack
pop rax ; load the value on top of the stack into rax
pop rcx ; load the value on top of the stack into rcx
xor rax,rcx ;
xor rcx,rax ; rcx = rcx ^ (rax ^ rcx) = rax
xor rax,rcx ; rax = (rax ^ rcx) ^ (rcx ^ (rax ^ rcx)) = rcx
add rax,rcx ;
sub rcx,rax ; rcx = rcx - (rax + rcx) = -rax
add rax,rcx ; rax = (rax + rcx) - rax = rcx
neg rcx ; rcx = 0 - rcx = 0 + rax = rax
xchg rax,rcx ; exchange the content of rax with rcx