tahsgh
Messages postés22Date d'inscriptionjeudi 17 avril 2008StatutMembreDernière intervention15 novembre 2010
-
24 avril 2010 à 00:01
cs_patatalo
Messages postés1466Date d'inscriptionvendredi 2 janvier 2004StatutModérateurDernière intervention14 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
cs_ghuysmans99
Messages postés3982Date d'inscriptionjeudi 14 juillet 2005StatutMembreDernière intervention30 juin 201316 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
tahsgh
Messages postés22Date d'inscriptionjeudi 17 avril 2008StatutMembreDernière intervention15 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?