forked from 0xdea/xorpd-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0x02.asm
36 lines (34 loc) · 852 Bytes
/
0x02.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
;
; $Id: 0x02.asm,v 1.1.1.1 2016/03/27 08:40:12 raptor Exp $
;
; 0x02 explanation - from xchg rax,rax by [email protected]
; Copyright (c) 2016 Marco Ivaldi <[email protected]>
;
; This snippet sets rax to 1 for all its initial values but
; 0, in which case it sets it to 0. To analyze it, I've used
; the handy assembly REPL rappel by [email protected]:
;
; https://github.com/yrp604/rappel/
;
; Example:
; $ ./rappel
; > mov rax,0
; > neg rax
; > sbb rax,rax
; > neg rax
; rax: 0x0000000000000000
; [...]
; > mov rax,1
; > neg rax
; > sbb rax,rax
; > neg rax
; rax: 0x0000000000000001
;
BITS 64
SECTION .text
global main
main:
;mov rax,1 ; initialize the rax register
neg rax ; two's complement (0 - rax); cf = 1 if rax != 0
sbb rax,rax ; rax - rax - cf (it can be either 0 or -1)
neg rax ; two's complement (it can be either 0 or 1)