what is rep scasw? - Programmers Heaven

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.

what is rep scasw?

omheromher Posts: 21Member
and what about repz scasw? Any more info on things that come after rep, or info what rep is precisely? I use rep stosw in graphics to move the double buffer to the video buffer, it moves data it seems in one instruction. But what about the others?

Comments

  • angelusMortisangelusMortis Posts: 141Member
    : and what about repz scasw? Any more info on things that come after rep, or info what rep is precisely? I use rep stosw in graphics to move the double buffer to the video buffer, it moves data it seems in one instruction. But what about the others?
    :

    rep means repeat. repZ means repeat while zero flag set.
    rep is only good in a loop . u can move a value to cx to set
    how often u want to repet an instruction.

    mov cx,32000 ; how often to loop
    rep scasw ; repeat 32000 times scasw

    will repeat scasw 32000 times.
    scasw means scan string ( wordwise ). this compares a string
    adressed by es:di with the ax-register. after this it will
    increase di by 2 .

    there r some other versions of rep. for example:
    repNZ ( repeat while not zero )
    repE ( repeat while equal )
    repNE ( repeat while not equal )

    but repe is the same as repz and repne is the same as repnz .
    u should buy a book about the basics of asm.

  • omheromher Posts: 21Member

    Thanks A lot!
    I do have a book on basic assembly (Assembly language Step by step). It explains rep stosw, so I understood rep, and it explains what the flags are, but I didn't know if it was rep affecting the flags or the string instruction. So since SCASW means SCAn String Word-wise, SCASB means SCAn String Byte-wise? And it increases di by 1? And what about CMPS? It compares a string of bytes? Then di would be increased by the string length? And are there any SCASD for doubles? Thanks for your help!

  • angelusMortisangelusMortis Posts: 141Member
    :
    : Thanks A lot!
    : I do have a book on basic assembly (Assembly language Step by step). It explains rep stosw, so I understood rep, and it explains what the flags are, but I didn't know if it was rep affecting the flags or the string instruction. So since SCASW means SCAn String Word-wise, SCASB means SCAn String Byte-wise? And it increases di by 1? And what about CMPS? It compares a string of bytes? Then di would be increased by the string length? And are there any SCASD for doubles? Thanks for your help!
    :

    the string instruction is causing the zeroflag. lets look what
    happens:
    if u compare something ur cpu will subtract the 2 things so:
    [code]
    cmp ax,bx ;
    jz @label ; here the cpu will jump if ax=bx
    [/code]

    the difference between a normal subtraction and compare is
    that cmp will never save the result, it will just set the flags.
    so if ax is equal to bx and u subtract ( ax-bx or bx-ax )
    the result will be 0 . the cpu will set the zeroflag. thats
    why u can write jz instead of je . all in all the flags are set
    by the scas instruction and repz just checks the zeroflag.

    yes scasb means scan string bytewise and increase di by 1.
    there is also a scasd for doubles. but u have to switch to
    386 instruction-mode before u can use it. remember 32bit-
    registers are not available for older cpus.

    cmps: this compares 2 strings :
    [code]
    cmps bstring1,bstring2 ; strings of byte
    cmps wstring1,wstring2 ; word
    cmps dstring1,dstring2 ; dword ( set 386 instructions )
    [/code]
    be sure that ds-register is set to the segment of string1 and
    es-register is set to the segment of string2.
    or u just set ds:si to the adress of string1 and es:si to
    the adress of string2.
    ur code might look like this:

    [code]
    push ds ; push ds to stack
    pop es ; and pop it to es so es=ds
    ; i assume that the strings r in the same segment
    mov si,offset string1 ; ds:si points to string1 now
    mov di,offset string2 ; es:di points to string2 now
    repe cmpsb ; repeat compare while equal ( zeroflag set )
    [/code]

    si and di will be increased by 1 ( bytewise) so that they point
    to the next bytes of each string. use cmpsw for wordwise,
    cmpsd for dwordwise ( again, 386 necessary :).







Sign In or Register to comment.