Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bits 32 ; assembling for the 32 bits architecture
- ; declare the EntryPoint (a label defining the very first instruction of the program)
- global start
- ; declare external functions needed by our program
- extern exit , printf ; tell nasm that exit exists even if we won't be defining it
- import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
- import printf msvcrt.dll ; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
- ; our data is declared here (the variables needed by our program)
- segment data use32 class=data
- a dw 1234h,5678h,90h
- l1 equ ($-a)/2
- b dw 104h,0abcdh,10h,1122h
- l2 equ ($-b)/2
- c resb l1+l2
- gasit db 0
- mesaj db "Sirul cifrelor este: ", 0
- ; our code starts here
- ;a. Se dau doua siruri de cuvinte a si b. Sa se obtina sirul c astfel:
- ;- concatenati sirul octetilor low din primul sir cu sirul octetilor high din al doilea sir.
- ;- sirul c se va ordona crescator
- ;- numerele din siruri se vor interpreta cu semn
- ;- afisati sirul c (numere in baza 16)
- ; Exemplu:
- ; a dw 1234h,5678h,90h
- ; b dw 4h,0abcdh,10h,1122h
- ; c resb 7
- ; Reprezentarea in memorie:
- ; a -> | 34h| 12h| 78h| 56h| 90h| 00h|
- ; b -> | 04h| 00h| 0cdh| 0abh| 10h| 00h| 22h| 11h|
- ; Dupa concatenare sirul c va fi: 34h,78h,90h,00h,0abh,00h,11h.
- ; Apoi se face ordonarea octetilor.
- segment code use32 class=code
- start:
- ;CREARE SIR
- mov ecx, l1
- mov esi, a
- cld
- mov ebx, 0 ; contor pt sirul destinatie
- jecxz eZero
- repeta:
- lodsw
- mov [c+ebx], al
- inc ebx
- loop repeta
- eZero:
- mov ecx, l2
- mov esi, b
- cld
- jecxz zero
- repp:
- lodsw
- shr ax, 8
- mov [c+ebx], al
- inc ebx
- loop repp
- zero:
- ;SORTARE
- mov ecx, l1
- add ecx, l2
- dec ecx
- jecxz ZERO
- do:
- ;.gasit db 0 ; variabila locala
- mov ecx, l1
- add ecx, l2
- dec ecx
- mov ebx, 0 ; contor pentru sirul ebx
- mov byte[gasit], 0 ;daca am gasit cel putin o interschimare atunci gasit va avea val 1
- cattimp:
- mov al, [c+ebx+1]
- mov dl, [c+ebx]
- cmp dl, al
- jle eMaiMare ; daca [c+ebx]<= [c+ebx+1] sare mai departe
- xchg [c+ebx], al
- mov [c+ebx+1], al
- mov byte[gasit], 1
- dec ebx
- eMaiMare:
- inc ebx
- loop cattimp
- cmp byte[gasit], 0
- je Sortat
- jmp do
- ZERO:
- Sortat:
- ; AFISARE SIR SORTAT:
- push dword mesaj
- call [printf]
- add esp, 4*1
- mov esi, c
- cld
- mov ecx, edi
- jecxz esteZero
- cttimp:
- xor eax, eax
- lodsb
- cbw
- cwde
- pushad
- push dword eax
- call [printf]
- add esp, 4*1
- popad
- loop cttimp
- esteZero:
- ; exit(0)
- push dword 0 ; push the parameter for exit onto the stack
- call [exit] ; call exit to terminate the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement