-
Notifications
You must be signed in to change notification settings - Fork 20
/
0x0b.asm
44 lines (42 loc) · 1.13 KB
/
0x0b.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
;
; $Id: 0x0b.asm,v 1.1.1.1 2016/03/27 08:40:12 raptor Exp $
;
; 0x0b explanation - from xchg rax,rax by [email protected]
; Copyright (c) 2016 Marco Ivaldi <[email protected]>
;
; This snippet performs either a neg (two's complement
; negation) or a not (one's complement negation) operation
; on the value present in rdx, based on the content of rax.
; Specifically, if rax contains 0, then a neg operation is
; performed; if rax contains any other value, a not
; operation is performed instead.
;
; Therefore, this snippet is roughly equivalent to the
; following C code:
;
; #include <stdio.h>
; main()
; {
; int rax = 0; // use 0 for neg, any other value for not
; int rdx = 5;
; printf("in rdx: %d\n", rdx);
; printf("in rax: %d\n", rax);
; if (rax)
; rdx = ~rdx; // not
; else
; rdx = ~rdx + 1; // neg
; printf("out rdx: %d\n", rdx);
; }
;
; This analysis was facilitated by the assembly REPL rappel
; by [email protected]:
;
; https://github.com/yrp604/rappel/
;
BITS 64
SECTION .text
global main
main:
not rdx ; rdx = ~rdx = 0 - (rdx + 1) = 0 - rdx - 1
neg rax ; cf = 1 if rax; cf = 0 if !rax
sbb rdx,-1 ; rdx = rdx + 1 - cf