Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %include "io.inc"
- section .bss
- esp_saved resd 1
- command resb 1
- num1 resd 1
- num2 resd 1
- section .data
- forms db '%s', 0
- formc db '%c', 0
- formd db '%d', 0
- formdd db '%d %d', 10, 0
- section .text
- global CMAIN
- CEXTERN scanf
- CEXTERN printf
- CEXTERN malloc
- CEXTERN free
- CEXTERN strcmp
- CMAIN:
- mov dword[esp_saved], esp
- and esp, -16
- sub esp, 16
- mov esi, 0
- .L:
- mov dword[esp], formc
- mov dword[esp + 4], command
- call scanf
- cmp byte[command], 'F'
- jz .IF
- cmp byte[command], 'A'
- jz .ELSEIF1
- cmp byte[command], 'S'
- jz .ELSEIF2
- cmp byte[command], 'D'
- jz .ELSEIF3
- jmp .L
- .IF: ;F
- jmp .E
- .ELSEIF1: ;A
- mov dword[esp], formdd
- mov dword[esp + 4], num1
- mov dword[esp + 8], num2
- call scanf
- mov dword[esp], esi
- mov ebx, dword[num1]
- mov dword[esp + 4], ebx
- mov ebx, dword[num2]
- mov dword[esp + 8], ebx
- call insert
- cmp esi, 0
- cmovz esi, eax
- jmp .L
- .ELSEIF2: ;S
- mov dword[esp], formd
- mov dword[esp + 4], num1
- call scanf
- mov dword[esp], esi
- mov ebx, dword[num1]
- mov dword[esp + 4], ebx
- call find
- cmp eax, 0
- jz .L
- mov dword[esp], formdd
- mov ebx, dword[eax]
- mov dword[esp + 4], ebx
- mov ebx, dword[eax + 4]
- mov dword[esp + 8], ebx
- call printf
- jmp .L
- .ELSEIF3: ;D
- mov dword[esp], formd
- mov dword[esp + 4], num1
- call scanf
- mov dword[esp], esi
- mov ebx, dword[num1]
- mov dword[esp + 4], ebx
- call delete
- mov esi, edx
- jmp .L
- .E:
- sub esp, 12
- push esi
- call erase
- add esp, 4
- .END:
- mov esp, dword[esp_saved]
- xor eax, eax
- ret
- global tree
- tree:
- push ebp
- mov ebp, esp
- sub esp, 12
- push ecx
- push edx
- push 16
- call malloc
- add esp, 4
- pop edx
- pop ecx
- add esp, 12
- mov edx, dword[ebp + 8]
- mov dword[eax], edx
- mov edx, dword[ebp + 12]
- mov dword[eax + 4], edx
- mov dword[eax + 8], 0
- mov dword[eax + 12], 0
- leave
- ret
- global insert
- insert:
- push ebp
- mov ebp, esp
- push ebx
- mov ebx, dword[ebp + 8]
- mov ecx, dword[ebp + 12]
- sub esp, 12
- push dword[ebp + 16]
- push dword[ebp + 12]
- call tree
- add esp, 20
- .L1:
- cmp ebx, 0
- jz .E1
- cmp ecx, dword[ebx]
- jz .IF1
- jg .ELSEIF11
- jl .ELSEIF12
- .IF1:
- mov ecx, dword[ebp + 16]
- mov dword[ebx + 4], ecx
- jmp .E1
- .ELSEIF11:
- cmp dword[ebx + 12], 0
- cmovnz ebx, dword[ebx + 12]
- jnz .L1
- cmovz edx, eax
- mov dword[ebx + 12], edx
- jz .E1
- .ELSEIF12:
- cmp dword[ebx + 8], 0
- cmovnz ebx, dword[ebx + 8]
- jnz .L1
- cmovz edx, eax
- mov dword[ebx + 8], edx
- jz .E1
- .ENDIF1:
- jmp .L1
- .E1:
- pop ebx
- leave
- ret
- global find
- find:
- push ebp
- mov ebp, esp
- cmp dword[ebp + 8], 0
- jz .IF2
- mov edx, dword[ebp + 8]
- mov edx, dword[edx]
- cmp edx, dword[ebp + 12]
- jz .IF2
- cmp dword[ebp + 12], edx
- jl .ELSEIF21
- jmp .ELSEIF22
- .IF2: ;ebp+8 == null || ebp+12 == [ebp+8]+0
- mov eax, dword[ebp + 8]
- jmp .ENDIF2
- .ELSEIF21: ;ebp+12 < [ebp+8]+0
- mov edx, dword[ebp + 8]
- mov edx, dword[edx + 8]
- push edx
- push dword[ebp + 16]
- push dword[ebp + 12]
- push edx
- call find
- add esp, 12
- pop edx
- jmp .ENDIF2
- .ELSEIF22: ;ebp+12 > [ebp+8]+0
- mov edx, dword[ebp + 8]
- mov edx, dword[edx + 12]
- push edx
- push dword[ebp + 16]
- push dword[ebp + 12]
- push edx
- call find
- add esp, 12
- pop edx
- jmp .ENDIF2
- .ENDIF2:
- leave
- ret
- global min
- min:
- push ebp
- mov ebp, esp
- mov eax, dword[ebp + 8]
- mov eax, dword[eax + 8]
- cmp eax, 0
- jz .IF3
- jmp .ELSEIF3
- .IF3: ;[ebp+8]+8 == null
- mov eax, dword[ebp + 8]
- jmp .ENDIF3
- .ELSEIF3:
- push eax
- call min
- add esp, 4
- jmp .ENDIF3
- .ENDIF3:
- leave
- ret
- global delete
- delete:
- push ebp
- mov ebp, esp
- push ebx
- mov ebx, dword[ebp + 8]
- cmp ebx, 0
- jz .IF4
- jmp .ENDIF4
- .IF4:
- mov edx, 0
- jmp .ENDdelete
- .ENDIF4:
- mov ebx, dword[ebx]
- cmp dword[ebp + 12], ebx
- mov ebx, dword[ebp + 8]
- jl .IF5
- jg .ELSEIF51
- mov ebx, dword[ebp + 8]
- cmp dword[ebx + 8], 0
- jz .ELSEIF53
- cmp dword[ebx + 12], 0
- jz .ELSEIF53
- jmp .ELSEIF52
- .IF5: ;ebp+12 < [ebp+8]+0
- push ebx
- sub esp, 8
- push dword[ebp + 12]
- push dword[ebx + 8]
- call delete
- add esp, 16
- pop ebx
- mov dword[ebx + 8], edx
- jmp .ENDIF5
- .ELSEIF51: ;ebp+12 > [ebp+8]+0
- push ebx
- sub esp, 8
- push dword[ebp + 12]
- push dword[ebx + 12]
- call delete
- add esp, 16
- pop ebx
- mov dword[ebx + 12], edx
- jmp .ENDIF5
- .ELSEIF52: ;[ebp+8]+8 != null && [ebp+8]+12 != null
- push dword[ebx + 12]
- call min
- add esp, 4
- mov edx, dword[eax]
- mov dword[ebx], edx
- mov edx, dword[eax + 4]
- mov dword[ebx + 4], edx
- push ebx
- sub esp, 8
- push dword[ebx]
- push dword[ebx + 12]
- call delete
- add esp, 16
- pop ebx
- mov dword[ebx + 12], edx
- jmp .ENDIF5
- .ELSEIF53:
- mov eax, ebx
- cmp dword[ebx + 8], 0
- jnz .IF6
- cmp dword[ebx + 12], 0
- jnz .ELSEIF61
- jmp .ELSEIF62
- .IF6:
- mov ebx, dword[ebx + 8]
- mov dword[ebp + 8], ebx
- jmp .ENDIF6
- .ELSEIF61:
- mov ebx, dword[ebx + 12]
- mov dword[ebp + 8], ebx
- jmp .ENDIF6
- .ELSEIF62:
- mov dword[ebp + 8], 0
- jmp .ENDIF6
- .ENDIF6:
- push eax
- call free
- add esp, 4
- jmp .ENDIF5
- .ENDIF5:
- mov edx, dword[ebp + 8]
- .ENDdelete:
- pop ebx
- leave
- ret
- global erase
- erase:
- push ebp
- mov ebp, esp
- cmp dword[ebp + 8], 0
- jz .ENDerase
- mov eax, dword[ebp + 8]
- push eax
- push dword[eax + 8]
- call erase
- add esp, 4
- pop eax
- push eax
- push dword[eax + 12]
- call erase
- add esp, 4
- pop eax
- push eax
- push dword[ebp + 8]
- call free
- add esp, 8
- .ENDerase:
- leave
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement