Problem en asm

tahsgh Messages postés 22 Date d'inscription jeudi 17 avril 2008 Statut Membre Dernière intervention 15 novembre 2010 - 24 avril 2010 à 00:01
cs_patatalo Messages postés 1466 Date d'inscription vendredi 2 janvier 2004 Statut Modérateur Dernière intervention 14 février 2014 - 24 avril 2010 à 03:10
salam,
j'ai le code suivant:
; bubble sort and swap subroutines saving and restoring registers
;[org 0x0100]
jmp start
data: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0
data2: dw 328, 329, 898, 8923, 8293, 2345, 10, 877, 355, 98
dw 888, 533, 2000, 1020, 30, 200, 761, 167, 90, 5
swapflag: db 0
swap: push ax ; save old value of ax
mov ax, [bx+si] ; load first number in ax
xchg ax, [bx+si+2] ; exchange with second number
mov [bx+si], ax ; store second number in first
pop ax ; restore old value of ax
ret ; go back to where we came from
bubblesort: push ax ; save old value of ax
push cx ; save old value of cx
push si ; save old value of si
dec cx ; last element not compared
shl cx, 1 ; turn into byte count
mainloop: mov si, 0 ; initialize array index to zero
mov byte [swapflag], 0 ; reset swap flag to no swaps
innerloop: mov ax, [bx+si] ; load number in ax
cmp ax, [bx+si+2] ; compare with next number
jbe noswap ; no swap if already in order


call swap ; swaps two elements
mov byte [swapflag], 1 ; flag that a swap has been done
noswap: add si, 2 ; advance si to next index
cmp si, cx ; are we at last index
jne innerloop ; if not compare next two
cmp byte [swapflag], 1 ; check if a swap has been done
je mainloop ; if yes make another pass
pop si ; restore old value of si
pop cx ; restore old value of cx
pop ax ; restore old value of ax
ret ; go back to where we came from
start: mov bx, data ; send start of array in bx
mov cx, 10 ; send count of elements in cx
call bubblesort ; call our subroutine
mov bx, data2 ; send start of array in bx
mov cx, 20 ; send count of elements in cx
call bubblesort ; call our subroutine again
mov ax, 0x4c00 ; terminate program
int 0x21



je suis sous linux, je le compile avec "nasm", il me genere ce résultat :

gcc -o asm2 asm2.o
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o: In function `_start':
/build/buildd/eglibc-2.10.1/csu/../sysdeps/i386/elf/start.S:115: undefined reference to `main'
asm2.o: In function `start':
asm2.asm:(.text+0x9d): relocation truncated to fit: R_386_16 against `.text'
asm2.asm:(.text+0xaa): relocation truncated to fit: R_386_16 against `.text'
collect2: ld returned 1 exit status



j'ai pas compris quel est le probléme, voulez vous m'expliquer par détail comment proceder,
Merci

4 réponses

cs_ghuysmans99 Messages postés 3982 Date d'inscription jeudi 14 juillet 2005 Statut Membre Dernière intervention 30 juin 2013 16
24 avril 2010 à 00:25
Utilise NASM sous une machine virtuelle DOS pour compiler et essayer tes programmes. Ca fait des siècles qu'on ne développe plus en 16 bits sur PC.
---
VB.NET is good ... VB6 is better
0
cs_patatalo Messages postés 1466 Date d'inscription vendredi 2 janvier 2004 Statut Modérateur Dernière intervention 14 février 2014 2
24 avril 2010 à 00:27
salut,

C'est un problème de format. gcc s'attends à une source 32 bits mais ton programme est en mode réel.

Tu devrais generer un executable msdos car linux n'est pas prévu pour avoir une compatibilité 16 bits or le format elf ne peut être que 32 bits.

@++
0
tahsgh Messages postés 22 Date d'inscription jeudi 17 avril 2008 Statut Membre Dernière intervention 15 novembre 2010
24 avril 2010 à 00:48
salam; Merci de votre réponse
comment compiler asm sous le msdos?
et comment le déboguer?
j'ai essayer avec nasm, mais c'est une commande inconnue pour lui,
comment faire alors?
0
cs_patatalo Messages postés 1466 Date d'inscription vendredi 2 janvier 2004 Statut Modérateur Dernière intervention 14 février 2014 2
24 avril 2010 à 03:10
re,


je n'avais pas fais attention mais tu stipule [ORG 0x100], ce qui implique un format d'executable .com.

"nasm -f bin -o monprog.com src.asm" te permettra de sortir un .com directement.

precise [bits 16] apres [org], cela assurera un binaire 16 bits.

@++
0
Rejoignez-nous