nevim Posted October 25, 2021 Report Share Posted October 25, 2021 (edited) Salut! Am si eu o intrebare de incepator in ASM x86 AT&T. Ideea este urmatoarea, vreau sa compar o variabila din memorie cu un numar, doar ca imi da un rezultat ciudat. Sigur imi scapa ceva, dar dupa vreo doua ore de debug si cautat pe net nu-mi dau seama despre ce e vorba. Nu stiu de ce intra pe jl. .data n: .long 2 gr: .asciz "gr" l: .asciz "l" e: .asciz "e" .text .globl _start _start: mov $n, %eax mov $2, %ebx cmp %eax, %ebx jg lbl_gr jl lbl_l je lbl_e lbl_gr: mov $4, %eax mov $1, %ebx mov $gr, %ecx mov 3, %edx int $0x80 jmp lbl_exit lbl_l: mov $4, %eax mov $1, %ebx mov $l, %ecx mov $2, %edx int $0x80 jmp lbl_exit lbl_e: mov $4, %eax mov $1, %ebx mov $e, %ecx mov $2, %edx int $0x80 jmp lbl_exit lbl_exit: mov $1, %eax mov $0, %ebx int $0x80 Ca sa rulez, am folosit: as --32 cmp.asm -o cmp.o ld -m elf_i386 cmp.o -o cmp ./cmp Edited October 25, 2021 by nevim Bad code Quote Link to comment Share on other sites More sharing options...
M2G Posted October 25, 2021 Report Share Posted October 25, 2021 Daca e ASM AT&T se pare ca pentru instructiuni, sursa si destinatia sunt inversate. Incearca sa inversezi instructiunile, gen: mov $n, %eax mov $2, %ebx cmp %eax, %ebx O sa devina: mov %eax, $n mov %ebx, $2 cmp %ebx, %eax Mai multe despre Intel vs AT syntax aici: http://asm.sourceforge.net/articles/linasm.html 4 Quote Link to comment Share on other sites More sharing options...
nevim Posted October 31, 2021 Author Report Share Posted October 31, 2021 Da, pana la urma am gasit. Postez aici in caz ca se uita cineva pe viitor mov $n, %eax ar fi trebuit sa fie mov n, %eax Quote Link to comment Share on other sites More sharing options...