-
Notifications
You must be signed in to change notification settings - Fork 20
/
0x0e.asm
50 lines (46 loc) · 1.17 KB
/
0x0e.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
46
47
48
49
50
;
; $Id: 0x0e.asm,v 1.1.1.1 2016/03/27 08:40:12 raptor Exp $
;
; 0x0e explanation - from xchg rax,rax by [email protected]
; Copyright (c) 2016 Marco Ivaldi <[email protected]>
;
; This snippet performs the following logical operations:
;
; rcx = rax
; rcx = ~(rcx & rbx)
; rax = ~rax | ~rbx
;
; This is an example application of DeMorgan's laws. Since
; rcx and rax have the same initial value, the resulting
; rcx and rax will still be equal, regardless of their
; initial value and of the initial value of rbx.
;
; This snippet is roughly equivalent to the following C
; code:
;
; #include <stdio.h>
; main()
; {
; int rax = 124; // arbitrary value
; int rbx = 666; // arbitrary value
; int rcx = rax;
; printf("in rax: %d\n", rax);
; printf("in rbx: %d\n", rbx);
; printf("in rcx: %d\n\n", rcx);
; rcx = ~(rcx & rbx);
; rax = ~rax | ~rbx;
; printf("out rax: %d\n", rax);
; printf("out rcx: %d\n", rcx);
; }
;
BITS 64
SECTION .text
global main
main:
mov rcx,rax ; initialize rax and rcx with the same value
and rcx,rbx ; rcx = rcx & rbx
not rcx ; rcx = ~rcx
not rax ; rax = ~rax
not rbx ; rbx = ~rbx
or rax,rbx ; rax = rax | rbx
cmp rax,rcx ; compare rax and rcx