×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

problem with looping

problem with looping

problem with looping

(OP)
the following code snippet copies from one place to another but doesn't want to decrement cx . An infinite loop has been created. can anyone tell me why and how I can fix it.
thanks




        .MODEL    SMALL
        .386

        .STACK    1024


        .DATA

Message        DB    'Press Any Key$'
videoSeg    =    0B800h
scrnStorage    =    (25*80*2)
buffer        DB     scrnStorage dup(?)

        .CODE
        
main        PROC

        
        mov    si,videoSeg        ;set DS to video segment
        mov    ds,si
        mov    si, 0            ; use as index
        
        mov    di,seg buffer        ;set ES to buffer
        mov    es,di
        mov    di,offset buffer    ; use as index
        mov    cx,scrnStorage        ;counter
        
        mov    dl,[si]            ;move video contents into buffer
        mov    es:[di],dl
        inc    si            ;move thru video memory
        inc    di            ;move thru buffer memory
        dec    cx            ;decrement counter
        cmp    cx,0
        jz    spot
        
        
    spot:

RE: problem with looping

Hello,

the only strange thing that I see is that you jump to spot, even though it arrives there anyway, so at spot, this code will have only have run once.
You probably mean something like:

main        PROC
        mov    si,videoSeg        ;set DS to video segment
        mov    ds,si
        mov    si, 0            ; use as index
        mov    di,seg buffer        ;set ES to buffer
        mov    es,di
        mov    di,offset buffer    ; use as index
        mov    cx,scrnStorage        ;counter
        rep    stosw
    spot:

Wouter Dijkslag
 
http://www.wody.demon.nl
 

RE: problem with looping

I'm not sure you can use the string to loop through as the counter, I think you might actually have to set the counter to the size of the string?

RE: problem with looping

Sorry, I misspoke.  Try setting the counter to the size of the string, plus one.

RE: problem with looping

(OP)
from:bigbeebrian

Thanks for all your help I think Ive got it now.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close