hey guys how are you all? i am working on a mini screen saver which moves the character 'A' to the end of the screen that gives the effect of it crawling on the screen. the problem with it is that the speed is too fast and i can see the character actually moving. so my teacher told me to slow the speed down we can waste the processor's time by doing unneccesary tasks.
my program works fine when i do not call the wastetime function. but when i call it the character doesnt print on the screen.
in the function waste time i am just doing some calculations that wil take the processor's time.

please note that i am working on x88 processor assembly language.

thanx guys also note that this question was given as a practice question to my class by my teacher.
also we have just finished printing the screen, and have done the basics and have just started the intermediate topics.

[org 0x0100]

jmp start

char: db 'A'

;main function of the program
	call clrscl

	mov ax,[char]
	push ax

	call printstr

	pop ax

	jmp endp
	;end main

;this clears the screen

	push bp
	mov bp,sp

	mov ax,0xb800
	mov es,ax
	mov di,0

	mov word[es:di],0x0720
	add di,2
	cmp di,4000
	jne clear
	pop bp
;end clear screen
;this sets up the screen memory
	push bp
	mov bp,sp
	mov ax,0xb800
	mov es,ax
	mov di,0

	call printchar

	pop bp

;end printstr

;this prints the character

	call remove

	call wastetime
	mov bx,[bp+4]
	mov bh,0x07
	mov word[es:di],bx
	add di,2

	cmp di,4000
	jne printchar

;end printcharacter
;this removes the previous printed character

	mov si,di
	sub si,2

	mov word[es:si],0x0720

;end remove

;this should waste the time of the compiler

			push bx
			push bp
			mov bp,sp
			sub sp,6
			mov si,0
			mov word[bp-2],4
			add bx,[bp-2]
			cmp bx,100
			jne wastetime
			add sp,6
			pop bp
			pop bx
;end the wastetime			


	mov ax,0x4c00
	int 0x21
8 Years
Discussion Span
Last Post by NotNull

> jne wastetime
Branch somewhere else, this keeps pushing stuff onto the stack and re-initialising your count.


A better way to slow down the progam than using instructions to give the processor
many operations, which in the case of assembly, could lead to errors,
is to use an empty loop of many iterations.
As a modification to your above code,
consider using your normal call to your waste time label,
and put the following code:

push cx         ; Push the old value of CX, since it will be your counter
mov cx,01000h  ; Put the value 1000h = 4096 dec in CX to loop 
                       ; 4,096 times
dec cx             ; decrement CX
jcxz exit_times   ; this conditional jump will exit when CX is zero
jmp loop_times  ; loop
pop cx              ; restore the old value of CX

ret                    ; pop the return address from the CALL 
                       ; instruction and
                       ; change the offset of IP, CS:IP to the next
                       ;  instruction after
                       ; the CALL instruction

As you can see in this modification of this routine BP and SP are not restored
since we do not change the value of BP, and SP is restored after the
POP CX instruction to its previous value,
the current offset of SP all the way down to the RET instruction will be
the return address pushed on the stack by the CALL instruction.

You should know with programs which use loops to slow down sprites
(text or otherwise), they will have unexpected results from machine
to machine.
Since you are in DOS, try the Get Time function AH=2C using INT 21h
to slow down your program.

This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.