Assembly Programming x86 Pentium Bug -
i'm having little problem in program written in assembly language x86 pentium. used debugger search abnormal thing in run of program. happening when try run in debugger goes when in terminal segmentation fault (core dumped) appears. know i'm accessing part of memory not defined see no problem on code.
here's code:
#.text #same .section .text .globl hell hell: push %ebp movl %esp, %ebp push %ebx #index push %edi push %esi subl $8, %esp movl 8(%ebp), %edx #str movl 12(%ebp), %eax #hist movl $-1, %esi xor %ecx, %ecx #j dec %ecx forclean: inc %ecx cmp $26, %ecx je for1 movl $0, (%eax, %ecx, 4) jmp forclean for1: inc %esi movb (%edx,%esi,1), %al cmpb $0, %al je fim cmpb $0x41, %al jl if2 cmpb $0x5a, %al jg if2 subb $0x41, %al movzbl %al, %ebx #mover para o index incl (%eax, %ebx, 4) jmp for1 if2: movb (%edx,%esi,1), %al cmpb $0x61, %al jl for1 cmpb $0x7a, %al jg for1 subb $0x61, %al movzbl %al, %ebx #mover para o index incl (%eax, %ebx, 4) jmp for1 end: movl %ebp, %esp popl %esi popl %edi popl %ebx popl %ebp ret
you store address of hist
in eax
, calculations character index inside al
. since part of eax
change address , that's why segmentation fault. clear ebx
register @ beginning , use bl
calculations instead.
also function's prolog , epilogue wrong. should be:
push %ebp movl %esp, %ebp subl $8, %esp #space local variables push %ebx push %edi push %esi
and
popl %esi popl %edi popl %ebx movl %ebp, %esp popl %ebp
Comments
Post a Comment