-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraysOperations.S
More file actions
81 lines (59 loc) · 1.98 KB
/
Copy pathArraysOperations.S
File metadata and controls
81 lines (59 loc) · 1.98 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#pragma GCC optimize ("Og")
#include <iostream>
using namespace std;
volatile uint16_t aa[5]={3,4,5,6,7},b;
volatile uint16_t i=3;
int main()
{
//b=aa[0];
// asm volatile //Lo conoce en tiempo de compilacion
// (
// "mov ax,[rip+aa] \n"
// "mov [rip+b],ax"
// :::"rax"
// );
//b=aa[2]; //Conoce en tiempo de compilacion
// asm volatile
// (
// "mov ax,[rip+aa+4] \n"
// "mov [rip+b],ax"
// :::"rax"
// );
//b=aa[i]; // Conoce en tiempo de ejecucion
// asm volatile
// (
// "mov ax,[rip+i] \n" //ax <-- (i)
// "movzx rax,ax \n" //rax <-- (i) en 64 bits
// "lea rdx,[rip+aa] \n" //rdx <-- dir de aa
// "mov ax,[rdx+rax*2] \n" //ax <-- (aa+(i)*2) <--> ax <-- (a[i]) /rax tiene i
// "mov [rip+b],ax"
// :::"rax","rdx"
// );
//Version simplificada
// asm volatile
// (
// "movx rax, word ptr[rip+i] \n" //ax <-- (i) en 64 bits //Tome 16 bits y extiendalo a 64
// "lea rdx,[rip+aa] \n" //rdx <-- dir de aa
// "mov ax,[rdx+rax*2] \n" //ax <-- (aa+(i)*2) <--> ax <-- (a[i]) /rax tiene i
// "mov [rip+b],ax"
// :::"rax","rdx"
// );
//b=aa[i-2]
asm volatile
(
"mov ax, [rip+i] \n"
"sub ax, 2 \n"
"movzx r8, ax \n"
"lea r9, [rip+aa] \n"
"mov ax, [r9+r8*2] \n"
"mov [rip+b],ax \n"
);
cout<<"b = "<<b<<endl;
return 0;
}