Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ***********************************************************************
- ; * File : lab8.asm
- ; * Author : your name here
- ; * Description: This program searches an array
- ; ***********************************************************************
- .386
- .MODEL FLAT
- ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
- PUBLIC _start ; make procedure _start public
- ; ***********************************************************************
- ; * Data Segment
- ; ***********************************************************************
- .DATA
- query DWORD 3 ; search query
- arr DWORD 1,2,3,4,5,1,3,5,7,9 ; creating array of 10 4-byte DWORDs
- found DWORD 0 ; 1 if query located in array, otherwise 0
- index DWORD 0 ; index of first appearance of query in array
- count DWORD 0 ; number of times query appears in array; ***********************************************************************
- ; * Stack Segment
- ; ***********************************************************************
- .STACK 4096
- ; ***********************************************************************
- ; * Code Segment
- ; ***********************************************************************
- .CODE
- _start PROC NEAR32 ; start procedure called _start
- ;
- mov esi, arr ; esi = arr
- mov edx, 0 ; edx = 0
- _loop:
- mov eax, [esi + edx * 4] ; eax = array[edx *4]
- inc edx ; edx = edx + 1
- cmp ecx, query ; compare ecx / query
- je _equal ; if ecx == query, jump to _equal
- cmp edx, 10 ; compare edx / 10
- je _loop ; if edx == 10, jump to _loop
- _equal:
- mov found, 1 ; found = 1
- cmp index, 0 ; compare index / 0
- je _set_index ; if index == 0, jump to _set_index
- cmp edx, 10 ; compare edx / 10
- je _loop ; if edx == 10, jump to _loop
- _set_index:
- mov index, edx ; index = edx
- cmp edx, 10 ; compare edx / 10
- je _loop ; if edx == 10, jump to _loop
- ;
- ;
- EVEN ; Make rest of code aligned on an even-addressed byte
- exit: INVOKE ExitProcess, 0 ; like return( 0 ); in C
- _start ENDP ; end procedure _start
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement