Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. lang equ ru
  2.  
  3. ;
  4. ;   Assembler
  5. ;     SMALL
  6. ;       CODE
  7. ;         Arrays
  8. ;           Processing
  9. ;             Libary
  10. ;
  11. ;   Ver 0.04
  12. ;
  13.  
  14. ; This macro iterates through an array of elements,
  15. ; processing each element using the specified process.
  16. ; modificate eax,{ebx},{ecx},edx,esi,[edi],[ebp]
  17.  
  18. macro array_processing object_array,process
  19. {
  20.  
  21.    movt edi,object_array
  22.    movt ebp,process
  23.    call array_processing_proc
  24.  
  25. if ~ defined array_processing_used
  26. array_processing_used equ 1
  27.    jmp end_ap
  28. array_processing_proc:
  29.    push ecx
  30.    push ebx
  31.    mov ecx,[edi]   ; dword contain quantity of elements
  32.    mov ebx,[edi+4] ; dword contain size of each element
  33.    add edi,8
  34. ap_read_next:
  35.    ;pop ebx
  36.    ;pop ecx
  37.    pushad
  38.    call ebp ;eax ;process
  39.    popad
  40.    ;push ecx
  41.    ;push ebx
  42.    add edi,ebx
  43.    dec ecx
  44.    jnz ap_read_next
  45.    pop ebx
  46.    pop ecx
  47.    ret
  48. end_ap:
  49. end if
  50. }
  51.  
  52. ; This macro iterates through an array of elements,
  53. ; processing each element using the specified process
  54. ; if object finded ina array macro returned
  55. ; with CF=0 and address of element in edi.
  56. ; if object not finded macro return CF=1
  57. ; process must be return CF=0 if value euqal finded value
  58. ; and CF=1 if value not equal
  59. ; modificate eax,{ebx},{ecx},edx,esi,[edi],[ebp]
  60.  
  61. macro array_find object_array,process
  62. {
  63.  
  64.    movt edi,object_array
  65.    movt ebp,process
  66.    call array_find_proc
  67.  
  68. if ~ defined array_find_used
  69. array_find_used equ 1
  70.    jmp end_af
  71. array_find_proc:
  72.    push ecx
  73.    push ebx
  74.    mov ecx,[edi]   ; dword contain quantity of elements
  75.    mov ebx,[edi+4] ; dword contain size of each element
  76.    add edi,8
  77. af_read_next:
  78.    pushad
  79.    call ebp ;eax ;process
  80.    popad
  81.    jnc af_finded
  82.    add edi,ebx
  83.    dec ecx
  84.    jnz af_read_next
  85. ; not finded
  86.    stc          ; if not finded CF = 1
  87. af_finded:         ; if finded CF = 0
  88.    pop ebx
  89.    pop ecx
  90.    ret
  91. end_af:
  92. end if
  93. }
  94.  
  95. ;
  96. ; process may get offests of elements from registers.
  97.  
  98. macro compmas object_array_1,object_array_2,process
  99. {
  100. local loo,loo2
  101.    ;lea,[oa+8]
  102.    mov esi,object_array_2     ; current position
  103.    add esi,8
  104.    mov ecx,[object_array_2]   ; dword contain quantity of elements
  105.    mov ebx,[object_array_2+4] ; dword contain size of each element
  106.    mov eax,0
  107. loo2:
  108.    push eax
  109.    mov edi,object_array_1     ; current position
  110.    add edi,8
  111.    mov ebp,[object_array_1]   ; dword contain quantity of elements
  112.    mov edx,[object_array_1+4] ; dword contain size of each element
  113.    mov eax,0 ;count
  114. loo:
  115.    pushad
  116.    call process
  117.    popad
  118.    add  edi,edx
  119.    inc  eax
  120.    cmp  eax,ebp
  121.    jne  loo
  122.    add  esi,ebx
  123.    pop  eax
  124.    inc  eax
  125.    cmp  eax,ecx
  126.    jne  loo2
  127. }
  128.  
  129.  
  130.  
  131. macro array_processing_nocall object_array,process
  132. {
  133. local read_next
  134.    lea edi,[object_array+8]
  135.    mov ecx,[object_array]    ; dword contain quantity of elements
  136. read_next:
  137.    pushad
  138.    call process
  139.    popad
  140.    add edi,[object_array+4] ; edi = edi + size of one element
  141.    dec ecx
  142.    jnz read_next
  143. }
  144.  
  145. macro array_find_nocall object_array,process
  146. {
  147. local read_next,finded
  148.    lea edi,[object_array+8] ; edi = current position
  149.    mov ecx,[object_array]   ; dword contain quantity of elements
  150. read_next:
  151.    pushad
  152.    call process
  153.    popad
  154.    jnc finded
  155.    add edi,[object_array+4] ; dword contain size of each element
  156.    dec ecx
  157.    jnz read_next
  158. ; not finded
  159.    stc          ; if not finded CF = 1
  160. finded:      ; if finded CF = 0
  161. }