演習として、yasm でバブルソートの始まりを書いています。しかし、私は以下の最後の命令で毎回セグメンテーション違反をしており、その理由がわかりません。
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 ; is a[i]>a[i+1]? <--- segfault here every time
;jump to swap next, if I could get there
私の理解では、cmpsb は si と di のバイトを比較します。なぜセグメンテーション違反になるのでしょうか? これは私の側では本当に単純なエラーに違いありませんが、私にはわかりません。通常、cmpsb は repe のコンテキストで使用されますが、ここでも機能すると思いました。助けてくれてありがとう!