Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Chris Ruskai
- TITLE CharacterSearch.asm
- INCLUDE Irvine32.inc
- PrepareMap PROTO,
- string: PTR BYTE,
- map: PTR BYTE
- CharacterSearch PROTO,
- map: PTR BYTE,
- char: BYTE
- .data
- stringMap byte 32 dup(0)
- testString byte "hello, assembly language programming!",0
- msg1 byte " is not in the string.",0
- msg2 byte " is in the string.",0
- ;Code test driver
- .code
- main PROC
- INVOKE PrepareMap, addr testString, addr stringMap
- ;Generate Random Characters
- call Randomize
- mov esi, 0
- L1:
- cmp esi, 9
- JG L2
- mov eax, 25
- call RandomRange
- add eax, 97d
- call WriteChar
- INVOKE CharacterSearch, addr stringMap, al
- inc esi
- JMP L1
- L2:
- exit
- main ENDP
- ;PrepareMap Procedure. Takes the test string and the map as parameters.
- PrepareMap PROC USES ECX EBX EAX EDX ESI EDI EBP, string: PTR BYTE, map: PTR BYTE
- ;mov string offsets and set counter
- mov esi, string
- mov edi, map
- mov edx, map
- mov ebp, 0
- ;for(int i = 0; i < strlength; i++)
- ForLoop:
- ;length of string
- cmp ebp, 32
- ;end loop if i >= 32
- JGE L9
- ;map[(string[i])>>3] |= 1<<( (string[i]) &7)
- ;map[(string[i]>>3]
- LeftSide:
- mov al, [esi]
- movzx eax, al
- shr eax, 3
- add edi, eax
- ;1 << ((string[i]) &7)
- RightSide:
- mov cl, [esi]
- AND cl, 7
- mov bl, 1
- shl bl, cl
- ; LefSide |= RightSide
- OrStatement:
- OR [edi], bl
- inc ebp
- inc esi
- mov edi, edx
- add edi, 1
- inc edx
- ;Restart loop
- JMP ForLoop
- ;End Loop
- L9:
- ret
- PrepareMap Endp
- CharacterSearch PROC map: PTR BYTE, char: BYTE
- ;map[ch >> 3]
- LeftSide:
- ;mov al, char
- ;call WriteChar
- mov edi, map
- mov cl, char
- shr cl, 3
- add [edi], cl
- ;(1 << ((string[i]) & 7)
- RightSide:
- mov cl, char
- AND cl, 7
- mov al, 1
- shl al, cl
- ;LeftSide & RightSide
- AndStatement:
- mov bl, [edi]
- AND bl, al
- ;If AndStatement != 0, character is here.
- IfStatement:
- cmp bl, 0
- JE NotIn
- mov edx, offset msg2
- call WriteString
- call crlf
- JMP L9
- ;Else, not in string.
- NotIn:
- mov edx, offset msg1
- call WriteString
- call crlf
- ;end proc
- L9:
- ret
- CharacterSearch endp
- END main
Add Comment
Please, Sign In to add comment