Advertisement
Guest User

Untitled

a guest
Apr 6th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section     .text
  2. global      _start
  3.  
  4. _start:
  5.  
  6.     ; Set elements of array
  7.         mov ECX, 1      ; Set number of iteration to ECX
  8.         mov ESI, array  ; Set address on first element of array
  9. setElement: mov EAX, 2      ; 2
  10.         imul    ECX     ; 2*i
  11.         add EAX, 10     ; 2*i+10
  12.         idiv    ECX     ; (2*i+10)/i
  13.         sub EAX, ECX    ; (2*i+10)/i-i
  14.         mov [ESI], EAX  ; Sets the i element to the array
  15.         inc ECX     ; Increment index of loop
  16.         add ESI, 4      ; Increment by 4 for next element of array
  17.         cmp ECX, 31     ; Comparing with limit of loop
  18.         jl  setElement  ; Repeat while ECX < 31
  19.  
  20.         mov     ECX, 1      ; Set number of interation to ECX
  21. researchElement:
  22.         mov EAX, [array+(ECX-1)*4]
  23. updateMinimum:
  24.         cmp     EAX, [minimum]
  25.         jg  addElementMod
  26.         mov [minimum], EAX
  27. addElementMod:
  28.         mov EBX, EAX
  29.         and EBX, 1
  30.         cmp EBX, 0
  31.         je  addElementDiv
  32.         mov     EBX, [arrayModCounter]
  33.         mov [arrayMod+4*EBX], EAX
  34.         inc EBX
  35.         mov [arrayModCounter], EBX
  36. addElementDiv:
  37.         xor EDX, EDX
  38.         mov EAX, [array+(ECX-1)*4]
  39.         mov ESI, 3
  40.         idiv    ESI
  41.         cmp EDX, 0
  42.         jne researchElementEnd
  43.         mov EAX, [array+(ECX-1)*4]
  44.         mov EBX, [arrayDivCounter]
  45.         mov [arrayDiv+4*EBX], EAX
  46.         inc EBX
  47.         mov [arrayDivCounter], EBX
  48. researchElementEnd:
  49.         inc ECX
  50.         cmp ECX, 31
  51.         jl  researchElement
  52.  
  53.     ; Print elements of array
  54.         mov     ECX, arrayDiv   ; Set address on first element of array
  55.         mov ESI, 1      ; Set number of iteration to ESI
  56.         mov EAX, 4      ; System call number (sys_write)
  57.         mov EBX, 1      ; File descriptor (stdout)
  58.         mov EDX, 4      ; Size of message
  59. printElements:  int 0x80        ; Print 32-bit value
  60.         inc ESI     ; Increment index of loop
  61.         add ECX, 4      ; Increment by 4 for next elemnt of array
  62.         cmp ESI, 31     ; Comparing with limit of loop
  63.         jl  printElements;  ; Repeat while ESI < 31
  64.  
  65.     ; Call to exit
  66.         mov EAX,1
  67.         int 0x80
  68.  
  69. section     .data
  70. array   times 30 dd 0           ; Allocate 30 elements of Double Word
  71. arrayDiv times 30 dd 0
  72. arrayMod times 30 dd 0
  73. arrayDivCounter   dd 0
  74. arrayModCounter   dd 0
  75. minimum       dd 0x7FFFFFFF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement