Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with looping

Status
Not open for further replies.

bigbeebrian

Programmer
Joined
Jan 15, 2001
Messages
9
Location
US
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:
 
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

 
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?
 
Sorry, I misspoke. Try setting the counter to the size of the string, plus one.
 
from:bigbeebrian

Thanks for all your help I think Ive got it now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top