Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

scan bit to bit

nklnkl Posts: 14Member
[b][red]This message was edited by nkl at 2005-10-12 3:0:19[/red][/b][hr]
may i know what is the way to scan into the data by scan bit to bit(scasb)? i just have this concept by using
mov ah, 06
but i don't have idea how to complete it in the assembly language(TASM)? so if somebody know please help me...Thanks


Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : [b][red]This message was edited by nkl at 2005-10-12 3:0:19[/red][/b][hr]
    : may i know what is the way to scan into the data by scan bit to bit(scasb)? i just have this concept by using
    : mov ah, 06
    : but i don't have idea how to complete it in the assembly language(TASM)? so if somebody know please help me...Thanks
    :
    :
    :
    [blue]SCASB is for searching BYTE (not bit) in array of bytes. I do not see how it is connected to MOV AH,06.
    [/blue]
  • nklnkl Posts: 14Member
    : : [b][red]This message was edited by nkl at 2005-10-12 3:0:19[/red][/b][hr]
    : : may i know what is the way to scan into the data by scan bit to bit(scasb)? i just have this concept by using
    : : mov ah, 06
    : : but i don't have idea how to complete it in the assembly language(TASM)? so if somebody know please help me...Thanks
    : :
    : :
    : :
    : [blue]SCASB is for searching BYTE (not bit) in array of bytes. I do not see how it is connected to MOV AH,06.
    : [/blue]
    : sorry may be i misunderstand. and thank you for telling me this important things!but do you know how to solve this problem?thanks...


  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : : : [b][red]This message was edited by nkl at 2005-10-12 3:0:19[/red][/b][hr]
    : : : may i know what is the way to scan into the data by scan bit to bit(scasb)? i just have this concept by using
    : : : mov ah, 06
    : : : but i don't have idea how to complete it in the assembly language(TASM)? so if somebody know please help me...Thanks
    : : :
    : : :
    : : :
    : : [blue]SCASB is for searching BYTE (not bit) in array of bytes. I do not see how it is connected to MOV AH,06.
    : : [/blue]
    : : sorry may be i misunderstand. and thank you for telling me this important things!but do you know how to solve this problem?thanks...
    :
    :
    :
    [blue]You should read about the SCASB instruction.
    I will try to explain a little: SCASB instruction is for finding a BYTE inside a buffer (or array of consecutive bytes). The instruction is used with these prefixes:

    REPNE SCASB - [b]REP[/b]eat instruction while AL [b]N[/b]ot [b]E[/b]qual contents of ES:DI

    REPE SCASB - [b]REP[/b]eat instruction while AL [b]E[/b]qual contents of ES:DI

    It means, that before theat instruction you have to set up the AL register with the BYTE you are trying to search and ES:DI address should be pointed to the address of buffer you are trying to look into.
    The number of search iterations must be in register CX.

    Also, DI register will be automatically moved every byte of the search, until of course, the condition REPE/REPNE is true. As soon as condition false (which means the BYTE was FOUIND!) - then it all stops and CPU moves to next instruction - after SCASB.

    The direction of the movement in DI register will be depending on Direction Flag. The value of that flag is set up with these instructions:

    CLD - CLear Direction (DI will be incremented in a search)
    STD - SeT Direction (DI will be decremented in a search, so you can scan for bytes backwards! - starting from the end of buffer)

    Important: When the BYTE is found - the DI register points to the NEXT byte after it. So, you need to adjust it properly.

    And here is a small code sample:
    [code]
    buffer db 'This text will be searched by SCASB!'
    ...

    ; ES register must be set up properly, but for COM file
    ; it is set up on the same segment, so we do not perform
    ; any additional setup. But if we have an EXE file - we need
    ; to make sure that ES is the same segment as the segment of
    ; that 'buffer' variable.

    MOV DI, OFFSET buffer ; Start scanning from the beginning
    MOV CX, 36 ; The symbol count in a 'buffer'
    MOV AL, 'w' ; Find that symbol!
    CLD ; move DI forward
    REPNE SCASB ; repeat while not equal
    JE @FoundIt ; jump if equal (search was a success)

    ; If you are here, then there is no such byte in buffer!
    ...

    @FoundIt:
    DEC DI ; adjust DI, because it points to a next symbol

    ; if you want to know the index of a BYTE:

    MOV AX, DI
    SUB AX, OFFSET buffer ; AX now is a zero-based index of a found BYTE
    [/code]
    [/blue]
Sign In or Register to comment.