-
Notifications
You must be signed in to change notification settings - Fork 20
/
0x07.asm
45 lines (43 loc) · 958 Bytes
/
0x07.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
36
37
38
39
40
41
42
43
44
45
;
; $Id: 0x07.asm,v 1.1.1.1 2016/03/27 08:40:12 raptor Exp $
;
; 0x07 explanation - from xchg rax,rax by [email protected]
; Copyright (c) 2016 Marco Ivaldi <[email protected]>
;
; This snippet sets rax with its initial value, in a way
; similar to the previous snippet 0x06. The following C
; code performs the same calculations:
;
; #include <stdio.h>
; main()
; {
; int rax = 5;
; printf("in: %d\n", rax);
; rax = ~((~(rax + 1) + 1) + 1) + 1;
; printf("out: %d\n", rax);
; }
;
; I guess the main takeway here (as in the previous snippet)
; is that "not rax" can be rewritten as:
;
; inc rax
; neg rax
;
; Similarly, "neg rax" can be rewritten as:
;
; not rax
; inc rax
;
; This analysis was facilitated by the assembly REPL rappel
; by [email protected]:
;
; https://github.com/yrp604/rappel/
;
BITS 64
SECTION .text
global main
main:
inc rax ; rax = rax + 1
neg rax ; rax = ~rax + 1
inc rax ; rax = rax + 1
neg rax ; rax = ~rax + 1