Advertisement
teejaybuckner

Untitled

Apr 26th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ***********************************************************************
  2. ; *  File : lab8.asm
  3. ; *  Author : your name here
  4. ; *  Description: This program searches an array
  5. ; ***********************************************************************
  6. .386
  7. .MODEL FLAT
  8. ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
  9. PUBLIC _start   ; make procedure _start public
  10. ; ***********************************************************************
  11. ; *                     Data Segment                                
  12. ; ***********************************************************************
  13. .DATA
  14. query   DWORD   3               ; search query
  15. arr DWORD 1,2,3,4,5,1,3,5,7,9           ; creating array of 10 4-byte DWORDs
  16. found   DWORD   0               ; 1 if query located in array, otherwise 0
  17. index   DWORD   0               ; index of first appearance of query in array
  18. count   DWORD   0               ; number of times query appears in array; ***********************************************************************
  19. ; *                     Stack Segment                                
  20. ; ***********************************************************************
  21. .STACK  4096
  22. ; ***********************************************************************
  23. ; *                     Code Segment                                  
  24. ; ***********************************************************************
  25. .CODE
  26. _start  PROC    NEAR32    ; start procedure called _start
  27. ;
  28.         mov esi, arr                ; esi = arr
  29.         mov edx, 0                      ; edx = 0
  30. _loop: 
  31.         mov eax, [esi + edx * 4]        ; eax = array[edx *4]
  32.         inc edx                 ; edx = edx + 1
  33.         cmp ecx, query              ; compare ecx & query
  34.         je _equal               ; if ecx == query, jump to _equal  
  35.         cmp edx, 10             ; compare edx & 10
  36.         je _loop                ; if edx == 10, jump to _loop
  37.        
  38. _equal:
  39.         mov found, 1                ; found = 1
  40.         cmp index, 0                ; compare index & 0
  41.         je _set_index               ; if index == 0, jump to _set_index
  42.         cmp edx, 10             ; compare edx & 10
  43.         je _loop                ; if edx == 10, jump to _loop
  44.        
  45. _set_index:
  46.         mov index, edx              ; index = edx
  47.         cmp edx, 10             ; compare edx & 10
  48.         je _loop                ; if edx == 10, jump to _loop
  49. ;
  50. ;
  51. EVEN            ; Make rest of code aligned on an even-addressed byte
  52. exit:   INVOKE  ExitProcess, 0  ; like return( 0 ); in C
  53. _start  ENDP                    ; end procedure _start
  54.         END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement