Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lg0; decomment according to platform (Linux or Windows)
- ;%include "include/io.lin.inc"
- %include "include/io.win.inc"
- section .text
- dd lg0 0
- dd lg1 0
- global do_operation
- ; TODO dissasemble the main.o file. Be sure not to overwrite registers used
- ; by main.o that he does not save himself.
- ; If you see your program going nuts, consider looking in the main.o disassembly
- ; for the causes mentioned earlier.
- do_operation:
- xor eax,eax
- xor ecx,ecx
- xor edx,edx
- xor ebx,ebx
- mov eax,[ebp+8] ;pointer care primu numar
- mov ebx,[ebp+12] ;pointer care al doilea numea
- mov ecx,[eax+4] ;lungimea primului nr
- mov edx,[ebx+4];lungimea numarului al doilea
- mov [lg0],ecx ;lg0 contine lungimea pentru primul nr
- mov [lg1],edx ;lg1 contine lg pentru al doilea nr
- mov ebx,[ebp+16] ; verific operatia
- cmp ebx,'|'
- jmp or_biti
- cmp ebx,'&'
- jmp and_biti
- or_biti: ;calculez sau pe biti pentru fiecare byte din numar
- mov ecx,[lg0]
- mov edx,[lg1]
- mov eax,[ebp+8]
- mov ebx,[ebp+12]
- cmp ecx,edx ;daca lungimea cea mai mica este a primului numar,o sa fac loop un loop care se termina cand lungimea acestuia se termina
- jl continuare
- continuare:
- mov ebx,[eax+8+ecx]
- mov ecx,ebx
- mov ebx,[ebp+12]
- mov eax,[ebx+8+edx]
- mov ebx,eax
- or ecx,ebx ; fac sau in bytes numarului
- mov edx,[lg0]
- mov eax,[ebp+8]
- mov [eax+8+edx],ecx ;pun informatia in memoria,in locul informatiei numarului de la ebp+8
- mov ecx,[lg0]
- dec ecx
- mov [lg0],ecx
- mov ebx,[lg1]
- dec ebx
- mov [lg1],ebx ;decrementez lungimile ambelor numere
- cmp ecx,0
- jne or_biti
- cmp ecx,0
- je final
- cmp ecx,edx ;daca lungimea celui de al doilea este mai mare,fac un loop care se termina cand lungimea acestuia se termina
- jge continuare2: ;proces identic cu cel de mai sus,difera doar momentul de oprire al loopului
- mov ebx,[eax+8+ecx]
- mov ecx,ebx
- mov ebx,[ebp+12]
- mov eax,[ebx+8+edx]
- mov ebx,eax
- or ecx,ebx
- mov edx,[lg0]
- mov eax,[ebp+8]
- mov [eax+8+edx],ecx
- mov ecx,[lg0]
- dec ecx
- mov [lg0],ecx
- mov ebx,[lg1]
- dec ebx
- mov [lg1],ebx
- cmp ebx,0
- jne or_biti
- cmp ebx,0
- je final
- jmp or_biti
- and_biti: ;intregul proces este identic cu or_biti,difera doar operatie de and in loc de or
- mov ecx,[lg0]
- mov edx,[lg1]
- mov eax,[ebp+8]
- mov ebx,[ebp+12]
- cmp ecx,edx
- jl continuare_si
- continuare_si:
- mov ebx,[eax+8+ecx]
- mov ecx,ebx
- mov ebx,[ebp+12]
- mov eax,[ebx+8+edx]
- mov ebx,eax
- or ecx,ebx
- mov edx,[lg0]
- mov eax,[ebp+8]
- mov [eax+8+edx],ecx
- mov ecx,[lg0]
- dec ecx
- mov [lg0],ecx
- mov ebx,[lg1]
- dec ebx
- mov [lg1],ebx
- cmp ecx,0
- jne and_biti
- cmp ecx,0
- je final
- cmp ecx,edx
- jge continuare2_si:
- mov ebx,[eax+8+ecx]
- mov ecx,ebx
- mov ebx,[ebp+12]
- mov eax,[ebx+8+edx]
- mov ebx,eax
- or ecx,ebx
- mov edx,[lg0]
- mov eax,[ebp+8]
- mov [eax+8+edx],ecx
- mov ecx,[lg0]
- dec ecx
- mov [lg0],ecx
- mov ebx,[lg1]
- dec ebx
- mov [lg1],ebx
- cmp ebx,0
- jne and_biti
- cmp ebx,0
- je final
- jmp and_biti
- final:
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement