Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern __imp__wsprintfA
- extern __imp__MessageBoxA@16
- extern __imp__ExitProcess@4
- extern __imp__malloc
- extern __imp__free
- %define MessageBox [__imp__MessageBoxA@16]
- %define wsprintf [__imp__wsprintfA]
- %define malloc [__imp__malloc]
- %define free [__imp__free]
- %macro getMem 1
- push %1
- call malloc
- add esp, 4
- %endmacro
- %macro freeMem 1
- push %1
- call free
- add esp, 4
- %endmacro
- MB_ICONINFORMATION equ 40h
- section .data
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; debug
- doutput db "number",0
- debugs db "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",0
- mb_title db "stack",0
- .code
- global _main
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; вектор
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; кладет в esi адрес выделенной памяти
- ;;портит ebx, eax
- vectorInit:
- mov ebx,8 ;размер вектора
- shl ebx,2
- add ebx,8
- push ebx
- getMem ebx
- pop ebx
- mov esi,eax
- mov dword[esi],0
- mov dword[esi+4],8
- sub ebx,4
- shr ebx,2
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;принимает значение и добавляет его в конец
- ;;портит eax, ebx, ecx, edx
- vectorAdd:
- mov eax,dword[esp+4]
- mov ebx,dword[esi+4]
- CondVectFull:
- cmp ebx,dword[esi]
- je vectIsFull
- jg vectIsNotFull
- vectIsFull:
- shl ebx,3
- add ebx,8
- getMem ebx
- mov ebx,dword[esi]
- inc ebx ;копируем колво занятых
- mov dword[eax],ebx
- mov ebx,dword[esi+4]
- shl ebx,1 ;копируем новый размер
- mov dword[eax+4],ebx
- mov ebx,dword[esi]
- add ebx,2
- mov ecx,1
- mov ebp,ebx
- copyVectorAdd:
- inc ecx
- cmp ebx,ecx
- jl endCopyVectorAdd
- mov edx,dword[esi+4*ecx]
- mov dword[eax+4*ecx],edx
- jmp copyVectorAdd
- endCopyVectorAdd
- mov ebx,dword[eax]
- mov ecx,dword[esp+4]
- mov dword[eax+4*ebx+4],ecx
- push eax
- freeMem esi
- pop esi
- jmp exitVectorAdd
- vectIsNotFull:
- mov ebx,9
- mov eax,dword[esi]
- inc eax
- mov dword[esi],eax
- mov ebx,dword[esp+4]
- dec eax
- mov dword[esi+4*eax+8],ebx
- exitVectorAdd:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; возвращает в eax значение последнего элемента
- ;;портит ebx, eсx, edx
- vectorPop:
- mov ebx,dword[esp+4]
- cmp ebx,0
- jl exitVectorPop
- cmp ebx,dword[esi]
- jge exitVectorPop
- mov eax,dword[esi+4]
- dec eax
- cmp eax,ebx
- jne moveVectPartLeft
- mov eax,dword[esi+4*ebx+8]
- mov ebx,dword[esi]
- sub ebx,4
- mov dword[esi],ebx
- jmp exitVectorPop
- mov ecx,dword[esi]
- moveVectPartLeft:
- cmp ebx,ecx
- jl endMoveVectPartLeft
- mov eax,dword[esi+4*ebx+8]
- mov ecx,dword[esi+4*ebx+12]
- mov dword[esi+4*ebx+8],ecx
- mov dword[esi+4*ebx+12],eax
- inc ebx
- jmp moveVectPartLeft
- endMoveVectPartLeft:
- mov ebx,dword[esi]
- dec ebx
- mov dword[esi],ebx
- ;;;
- mov ecx,dword[esi+4]
- cmp ecx,9
- jle exitVectorPop
- ;;;
- shr ecx,2
- cmp ebx,ecx
- jge exitVectorPop
- mov ebx,dword[esi+4]
- add ebx,8
- getMem ebx
- mov ebx,dword[esi]
- dec ebx ;копируем колво занятых
- mov dword[eax],ebx
- mov ebx,dword[esi+4]
- shr ebx,2 ;копируем новый размер
- mov dword[eax+4],ebx
- mov ebx,dword[esi]
- add ebx,2
- mov ecx,1
- mov ebp,ebx
- copyVectorPop:
- inc ecx
- cmp ebx,ecx
- jl endCopyVectorPop
- mov edx,dword[esi+4*ecx]
- mov dword[eax+4*ecx],edx
- jmp copyVectorPop
- endCopyVectorPop
- mov ebx,dword[eax]
- mov ecx,dword[esp+4]
- mov dword[eax+4*ebx+4],ecx
- push eax
- freeMem esi
- pop esi
- jmp exitVectorPop
- exitVectorPop:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; принемает индекс, с которого ищет
- ;; возвращает знач индекс макс элемента в eax
- ;; портит ebx, ecx
- vectorGetMaxIndex:
- mov ecx,dword[esp+4] ;ecx - counter
- call vectorIsEmpty
- cmp eax,1
- je vectorGetMaxIndexExit
- cmp ecx,dword[esi]
- jge vectorGetMaxIndexExit
- cmp ecx,0
- jl vectorGetMaxIndexExit
- push ecx ;текущий макс
- dec ecx
- vectorGetMaxIndexCycle:
- inc ecx
- cmp ecx,dword[esi]
- je vectorGetMaxIndexCycleEnd
- pop ebx
- push ebx
- mov eax,dword[esi+4*ebx+8]
- mov ebx,[esi+4*ecx+8]
- cmp ebx,eax
- jle vectorGetMaxIndexCycle
- pop eax
- push ecx
- jmp vectorGetMaxIndexCycle
- vectorGetMaxIndexCycleEnd:
- pop eax
- vectorGetMaxIndexExit:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; принемает индекс, с которого ищет
- ;; возвращает знач индекс мин элемента в eax
- ;; портит ebx, ecx
- vectorGetMinIndex:
- mov ecx,dword[esp+4] ;ecx - counter
- call vectorIsEmpty
- cmp eax,1
- je vectorGetMinIndexExit
- cmp ecx,dword[esi]
- jge vectorGetMinIndexExit
- cmp ecx,0
- jl vectorGetMinIndexExit
- push ecx ;текущий мин
- dec ecx
- vectorGetMinIndexCycle:
- inc ecx
- cmp ecx,dword[esi]
- je vectorGetMinIndexCycleEnd
- pop ebx
- push ebx
- mov eax,dword[esi+4*ebx+8]
- mov ebx,[esi+4*ecx+8]
- cmp ebx,eax
- jge vectorGetMinIndexCycle
- pop ebx
- push ecx
- jmp vectorGetMinIndexCycle
- vectorGetMinIndexCycleEnd:
- pop ebx
- ; mov eax,ebx
- vectorGetMinIndexExit:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; принимает значение а и индекс i, приравневает iый эл к a
- ;; портит ebx
- vectorSort:
- call vectorIsEmpty
- cmp eax,1
- je vectorSortExit
- mov edx, 0 ;edx - counter внешнего цикла
- mov eax,dword[esi]
- cmp eax,1
- je vectorSortExit
- dec edx
- vectorSortCycle:
- inc edx
- ; mov eax,dword[esi]
- ; dec eax
- cmp edx,2;eax ; == n ?
- je vectorSortExit
- push edx
- call vectorGetMinIndex
- pop edx
- ;;swap нач
- mov ebx, dword[esi+4*eax+8]
- mov ecx, dword[esi+4*edx+8]
- mov dword[esi+4*edx+8],ebx
- mov dword[esi+4*eax+8],ecx
- ;;swap кон
- jmp vectorSortCycle
- vectorSortExit:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; принимает индекс i, возвращает в eax индекс iого элемента
- vectorGet:
- mov eax,dword[esp+4] ;;where
- cmp eax,0
- jl exitVectorGet
- cmp eax,dword[esi]
- jge exitVectorGet
- mov eax, dword[esi+4*eax+8]
- exitVectorGet:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; возвращает 0 или 1 в eax если vector пуст или не пуст соотв.
- vectorIsEmpty:
- mov eax,dword[esi]
- cmp eax,0
- je vectorIsEmptyTrue
- mov eax,0
- jmp exitFromVectorIsEmpty
- vectorIsEmptyTrue:
- mov eax,1
- exitFromVectorIsEmpty:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- vectorClear:
- freeMem esi
- call vectorInit
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; возвращает первый элемент в eax
- vectorFirst:
- call vectorIsEmpty
- cmp eax,1
- je exitVectorFirst
- mov eax, dword[esi+8]
- exitVectorFirst:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; возвращает последний элемент в eax
- vectorLast:
- call vectorIsEmpty
- cmp eax,1
- je exitVectorLast
- mov eax,dword[esi]
- mov eax,dword[esi+4*eax+4] ;;+8-4
- exitVectorLast:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- vectorDestructor:
- freeMem esi
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; итератор по вектору.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- vectorIteratorInit:
- getMem 8
- mov dword[eax],0
- mov dword[eax+4],1
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- vectorIteratorHasNext:
- mov eax,dword[esp+4]
- mov eax,dword[eax+4]
- mov ebx,dword[esi]
- cmp eax,ebx
- jg vectorIteratorHasNextFalse
- mov eax,1
- jmp vectorIteratorHasNextExit
- vectorIteratorHasNextFalse:
- mov eax,0
- vectorIteratorHasNextExit:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- vectorIteratorNext:
- mov eax,dword[esp+4]
- push eax
- call vectorIteratorHasNext
- pop ebx
- cmp eax,0
- je vectorIteratorNextExit
- mov eax,dword[esp+4]
- mov ebx,dword[eax+4]
- mov dword[eax],ebx
- inc ebx
- mov dword[eax+4],ebx
- mov eax,dword[esi+4*ebx]
- vectorIteratorNextExit:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- vectorIteratorHasPrev:
- mov eax,dword[esp+4]
- mov eax,dword[eax]
- cmp eax,0
- jle vectorIteratorHasPrevFalse
- mov eax,1
- jmp vectorIteratorHasPrevExit
- vectorIteratorHasPrevFalse:
- mov eax,0
- vectorIteratorHasPrevExit:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- vectorIteratorPrev:
- mov eax,dword[esp+4]
- push eax
- call vectorIteratorHasPrev
- pop ebx
- cmp eax,0
- je vectorIteratorPrevExit
- mov eax,dword[esp+4]
- mov ebx,dword[eax]
- mov dword[eax+4],ebx
- dec ebx
- mov dword[eax],ebx
- mov eax,dword[esi+4*ebx+8]
- vectorIteratorPrevExit:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- vectorIteratorDestructor:
- mov eax,dword[esp+4]
- freeMem eax
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- _main:
- jmp begin
- begin:
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; инициализируем стек нулями, чтобы выводить даже если меньше параметров на стеке
- push 0
- push 0
- push 0
- push 0
- push 0
- push 0
- push 0
- push 0
- push 0
- push 0
- push 0
- push 0
- push 0
- push 0
- push 0
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- call vectorInit
- call vectorIteratorInit
- push 9
- call vectorAdd
- pop ebx
- push 2
- call vectorAdd
- pop ebx
- push 6
- call vectorAdd
- pop ebx
- push 4
- call vectorAdd
- pop ebx
- push 2
- call vectorAdd
- pop ebx
- push 7
- call vectorAdd
- pop ebx
- push 2
- call vectorAdd
- pop ebx
- push 3
- call vectorAdd
- pop ebx
- push 2
- call vectorAdd
- pop ebx
- push 6
- call vectorAdd
- pop ebx
- push 7
- call vectorGetMinIndex
- pop ecx
- push ebx
- call vectorDestructor
- call vectorIteratorDestructor
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; выведем содержимое последних 15 символов на стеке
- push debugs
- push doutput
- call wsprintf
- push MB_ICONINFORMATION
- push mb_title
- push doutput
- push 0
- call MessageBox
- push 0
- call [__imp__ExitProcess@4]
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ret ; завершение программы
- end
Add Comment
Please, Sign In to add comment