why segment fault?
the code i wrote is to find the biggest number in num,but it shows segment fault when i run it.
nasm -f elf and.asm -o and.o gcc -o and.o ./and segment fault //////////////////////////////////// section .data num db -19,28,37,-46,55,61,-74,88 count equ $-num max db 'max=?',0dh,0ah,'$' section .text global main main: mov al,0 mov ebx,num mov ecx,[count] last: cmp [ebx],al jc next mov al,[ebx] next: inc ebx loop last mov [max+4],al mov eax,4 mov ebx,1 mov ecx,max mov edx,8 int 80h mov eax,1 int 80h |
I can't help with your seg fault problem, but your initalization seems wrong. You've started with a value of zero, and -- if your data was all less than zero -- your logic would return zero instead of the largest value.
Also, I think you're comparing the character byte values rather than the numeric values represented by the set of bytes. (I may be wrong on this point -- its been thirty years since I last did asembly programming, and that was on an IBM 3090.) |
thank you very much Mr. PTrenholme. your suggestion seems much vulable. I'll try again. thank you again.
|
All times are GMT -5. The time now is 04:52 PM. |