Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .text
- global _start
- _start:
- ; Set elements of array
- mov ECX, 1 ; Set number of iteration to ECX
- mov ESI, array ; Set address on first element of array
- setElement: mov EAX, 2 ; 2
- imul ECX ; 2*i
- add EAX, 10 ; 2*i+10
- idiv ECX ; (2*i+10)/i
- sub EAX, ECX ; (2*i+10)/i-i
- mov [ESI], EAX ; Sets the i element to the array
- inc ECX ; Increment index of loop
- add ESI, 4 ; Increment by 4 for next element of array
- cmp ECX, 31 ; Comparing with limit of loop
- jl setElement ; Repeat while ECX < 31
- mov ECX, 1 ; Set number of interation to ECX
- researchElement:
- mov EAX, [array+(ECX-1)*4]
- updateMinimum:
- cmp EAX, [minimum]
- jg addElementMod
- mov [minimum], EAX
- addElementMod:
- mov EBX, EAX
- and EBX, 1
- cmp EBX, 0
- je addElementDiv
- mov EBX, [arrayModCounter]
- mov [arrayMod+4*EBX], EAX
- inc EBX
- mov [arrayModCounter], EBX
- addElementDiv:
- xor EDX, EDX
- mov EAX, [array+(ECX-1)*4]
- mov ESI, 3
- idiv ESI
- cmp EDX, 0
- jne researchElementEnd
- mov EAX, [array+(ECX-1)*4]
- mov EBX, [arrayDivCounter]
- mov [arrayDiv+4*EBX], EAX
- inc EBX
- mov [arrayDivCounter], EBX
- researchElementEnd:
- inc ECX
- cmp ECX, 31
- jl researchElement
- ; Print elements of array
- mov ECX, arrayDiv ; Set address on first element of array
- mov ESI, 1 ; Set number of iteration to ESI
- mov EAX, 4 ; System call number (sys_write)
- mov EBX, 1 ; File descriptor (stdout)
- mov EDX, 4 ; Size of message
- printElements: int 0x80 ; Print 32-bit value
- inc ESI ; Increment index of loop
- add ECX, 4 ; Increment by 4 for next elemnt of array
- cmp ESI, 31 ; Comparing with limit of loop
- jl printElements; ; Repeat while ESI < 31
- ; Call to exit
- mov EAX,1
- int 0x80
- section .data
- array times 30 dd 0 ; Allocate 30 elements of Double Word
- arrayDiv times 30 dd 0
- arrayMod times 30 dd 0
- arrayDivCounter dd 0
- arrayModCounter dd 0
- minimum dd 0x7FFFFFFF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement