Ensamblador - violación de segmento en nasm... no logro dar con el problema

 
Vista:
sin imagen de perfil

violación de segmento en nasm... no logro dar con el problema

Publicado por Adrian (1 intervención) el 28/06/2016 15:22:28
Hola, llevo mucho tiempo intentando resolver esta violación de segmento pero no logro dar con el problema...


El programa en NASM es el siguiente, y genera violación de segmento, llevo horas trackeando el error pero no logro encontrarlo... este código es generado por un compilador que estoy haciendo, y en lugar de devolver un 30 y una violación de segmento debería devolver un 30 y el mensaje: "****Error de ejecucion: overflow en resta"

Este es el código:


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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
segment .bss
   _x resd 1
   _ressuma resd 1
   _resproducto resd 1
   _resresta resd 1
 
segment .data
   mensaje_1 db "Indice fuera de rango", 0
   mensaje_2 db "Division por cero", 0
   mensaje_3 db "****Error de ejecucion: overflow en suma", 0
   mensaje_4 db "****Error de ejecucion: overflow en resta", 0
   mensaje_5 db "****Error de ejecucion: overflow en producto", 0
 
segment .text
   global main
   extern scan_int, scan_boolean
   extern print_int, print_boolean, print_string, print_blank, print_endofline
 
 
_suma:
push ebp
mov ebp , esp
sub esp , 4*1
lea eax , [ebp+12]
push dword eax
lea eax , [ebp+8]
push dword eax
pop dword edx
mov dword edx , [edx]
pop dword eax
mov dword eax , [eax]
add eax , edx
jo near error_3
push dword eax
pop dword eax
mov dword [ebp-4], eax
lea eax, [ebp-4]
push dword eax
pop dword eax
mov eax , [eax]
mov dword esp , ebp
pop dword ebp
ret
mov esp , ebp
pop ebp
ret
 
_resta:
push ebp
mov ebp , esp
sub esp , 4*1
lea eax , [ebp+12]
push dword eax
lea eax , [ebp+8]
push dword eax
pop dword edx
mov dword edx , [edx]
pop dword eax
mov dword eax , [eax]
sub eax , edx
jo near error_4
push dword eax
pop dword eax
mov dword [ebp-4], eax
lea eax, [ebp-4]
push dword eax
pop dword eax
mov eax , [eax]
mov dword esp , ebp
pop dword ebp
ret
mov esp , ebp
pop ebp
ret
 
_producto:
push ebp
mov ebp , esp
sub esp , 4*1
lea eax , [ebp+12]
push dword eax
lea eax , [ebp+8]
push dword eax
pop dword ecx
mov dword ecx , [ecx]
pop dword eax
mov dword eax , [eax]
imul ecx
jo near error_5
push dword eax
pop dword eax
mov dword [ebp-4], eax
lea eax, [ebp-4]
push dword eax
pop dword eax
mov eax , [eax]
mov dword esp , ebp
pop dword ebp
ret
mov esp , ebp
pop ebp
ret
 
main:
push dword 2147483647
pop dword eax
mov dword [_x],eax
push dword 10
push dword 20
call _suma
add esp , 4*2
push dword eax
pop dword eax
mov dword [_ressuma],eax
push dword _ressuma
pop dword eax
mov dword eax , [eax]
push dword eax
call print_int
add esp , 4
call print_endofline
 
mov dword eax, [_x]
push dword eax
pop dword eax
mov dword eax , [eax]
neg eax
push dword eax
 
mov dword eax, [_x]
push dword eax
call _resta
add esp , 4*2
push dword eax
pop dword eax
mov dword [_resresta],eax
push dword _resresta
pop dword eax
mov dword eax , [eax]
push dword eax
call print_int
add esp , 4
call print_endofline
 
mov dword eax, [_x]
push dword eax
push dword 10
call _producto
add esp , 4*2
push dword eax
pop dword eax
mov dword [_resproducto],eax
push dword _resproducto
pop dword eax
mov dword eax , [eax]
push dword eax
call print_int
add esp , 4
call print_endofline
 
fin: ret
error_1: push dword mensaje_1
      call print_string
      add esp , 4
      call print_endofline
      jmp near fin
error_2: push dword mensaje_2
      call print_string
      add esp , 4
      call print_endofline
      jmp near fin
error_3: push dword mensaje_3
      call print_string
      add esp , 4
      call print_endofline
      jmp near fin
error_4: push dword mensaje_4
      call print_string
      add esp , 4
      call print_endofline
      jmp near fin
error_5: push dword mensaje_5
      call print_string
      add esp , 4
      call print_endofline
      jmp near fin



Muchas gracias por vuestro tiempo...
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder