-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.mac
131 lines (108 loc) · 2.24 KB
/
string.mac
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
; --->> macros de escritura y lectura <<---
%define sys_read 0
%define sys_write 1
%define std_in 1
%define std_out 1
%define std_err 2
%define sys_exit 60
; std_out & std_in
%macro print 2 ; mensaje , lenMensaje
push rax
push rdi
push rsi
push rdx
mov rax, sys_write
mov rdi, std_out
mov rsi, %1
mov rdx, %2
syscall
pop rdx
pop rsi
pop rdi
pop rax
%endmacro
%macro leer 2 ;in = buffer, len out = len lecura en r8,
; push rax
push rdi
push rsi
push rdx
mov rax, sys_read
mov rdi, std_in
mov rsi, %1
mov rdx, %2
syscall
; len de lectura = rax
pop rdx
pop rsi
pop rdi
; pop rax
%endmacro
%macro movBuf 2 ; copia un buffer de tamaño rcx a otro de igual tamaño
push rcx
lea rdi, [%1]
lea rsi, [%2]
rep movsb
pop rcx
; ret
%endmacro
%macro exit 0
xor rsi, rsi
mov rax, sys_write
mov rdi, std_out
mov rsi, 0x0A
mov rdx, 1
syscall
mov rax, sys_exit
mov rdi, 0 ; return 0, success
syscall
%endmacro
;*****************
%macro rotarBufIzq 2 ; buffer (de Tamaño 26) , cantidad de rotaciones
push rcx
push r8
push rdi
push rsi
xor rcx, rcx
mov rcx, 26
mov r8, %2
movBuf bufTmp, %1
sub rcx, %2
lea rsi, [bufTmp + %2]
lea rdi, [%1]
rep movsb
lea rsi, [bufTmp]
xor rcx, rcx
mov rcx, %2
rep movsb
pop rsi
pop rdi
pop r8
pop rcx
%endmacro
;********************
%macro rotarBufDer 1 ; buffer (de Tamaño 26) , cantidad de rotaciones
push rcx
push r8
push rdi
push rsi
push rax
xor rcx, rcx
mov rcx, 26
; mov r8, %2
mov al, byte[%1 + 25] ;ultima letra
movBuf bufTmp, %1
sub rcx, 1
lea rsi, [bufTmp]
lea rdi, [%1 + 1]
rep movsb
mov byte [%1], al
; lea rsi, [bufTmp]
; xor rcx, rcx
; mov rcx, %2
; rep movsb
pop rax
pop rsi
pop rdi
pop r8
pop rcx
%endmacro