-
Notifications
You must be signed in to change notification settings - Fork 0
/
validarParentesis.asm
109 lines (91 loc) · 2.85 KB
/
validarParentesis.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
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
section .bss
textIn: resb 1024
lenTextIn: equ $ - textIn
section .data
msgErrRead: db "Info!. No se ingresaron datos.",0x0A
lenMsgErrRead: equ $ - msgErrRead
msgFail: db "Error. Paréntesis mal empleados",0x0A
lenMsgFail: equ $ - msgFail
msgOk: db "Validación aprobada.",0x0A
lenMsgOk: equ $ - msgOk
section .text
global _start
_start
main:
call read
call validar2829
jmp main
call exit
validar2829:
xor r9, r9 ;contador
xor r10, r10 ;resultados de validación
.validar:
cmp byte [textIn + r9], '('
je .case1
cmp byte [textIn + r9], ')'
je .case2
cmp r8, r9
je .case3
jne .continue
.case1:
cmp byte [textIn+ r9 + 1 ], ')'
je printErrValidacion
inc r10
jmp .continue
.case2:
dec r10
cmp r10, -1
je printErrValidacion
jmp .continue
.case3:
cmp r10, 0
je printMsgOk
jne printErrValidacion
.continue
inc r9
jmp .validar
read:
mov rax, 0 ;sys_read
mov rdi, 1 ;std_in
mov rsi, textIn
mov rdx, lenTextIn
syscall
;comprobar lectura. Sale si ctel + d
cmp rax, 0
je exit
dec rax ;!!!! enter
mov r8, rax ;guardar len
ret
printMsgOk:
mov rsi, msgOk
mov rdx, lenMsgOk
call print
ret
printErrLectura:
mov rsi, msgErrRead
mov rdx, lenMsgErrRead
call printError
printErrValidacion:
mov rsi, msgFail
mov rdx, lenMsgFail
call printError
printError:
mov rax, 1 ;sys_write
mov rdi, 2 ;std_err
syscall
;ret
call exit
print:
mov rax, 1 ;sys_write
mov rdi, 1 ;std_out
syscall
ret
exit:
xor rsi, rsi
mov rsi, 0x0a
mov rdx, 1
call print
mov rax, 60 ;sys_exit
mov rdi, 0 ; return 0, success
syscall
;end exit