Wednesday, 15 July 2015

assembly - x86 yasm, segfault on cmpsb; proper usage of cmpsb? -



assembly - x86 yasm, segfault on cmpsb; proper usage of cmpsb? -

i'm writing origin of bubble sort in yasm, exercise. i'm segfaulting every time @ lastly instruction below , don't understand why.

segment .data arr db 5,6,2,3,8,1 segment .text global main main: xor ecx, ecx ; counter mov rdx, 6 ; sizeof(arr) cld _do: xor eax, eax ; set swapped = false for: movzx esi, byte [arr+ecx] movzx edi, byte [arr+ecx+1] cmpsb ; a[i]>a[i+1]? <--- segfault here every time ;jump swap next, if there

my understanding cmpsb compares byte in si , di. why should segfault? must simple error on part don't see it. cmpsb used in context of repe, thought work here too. help!

cmpsb doesn't compare contents of 2 registers -- that's normal cmp for. instead, treats registers addresses , compares 2 values point to. seek like:

lea esi, byte [arr + ecx] lea edi, byte [arr + ecx + 1] cmpsb

assembly x86 yasm

No comments:

Post a Comment