Sign in to follow this  
Hauk

8086 ASM help needed :(

Recommended Posts

Hey guys, I've a lab exam next week in assembly language programming, and I can't for the life of me get 'Hello' to bounce around the scree. Our lecturer gave us a program to practise with, but I just can't get it. I've been trying for a good hour and a half, and nothing is working. The message just floats off the screen.
; text with color
.model small
.stack 200h
.data
		text db "Hello"
		Color db 0ECh
		Slength dw 5
		Row db 0
		Col db 0
		RowTst db 1
		ColTst db 1

.code

start_main:
		mov cx,50
back:	call blank
		call print_txt
		inc Col
		inc Row
		cmp Row, 79
		jz set_row
		cmp Col, 24
		jz set_col
		call delay
		loop back
		call get_key
		call exit
		
set_col: mov ah, ColTst
		add Col, ah
		xor ax,ax
		ret

set_row: mov ah, RowTst
		add Row, ah
		ret

get_key:
	push ax
	mov ah,00h
	int 16H
	pop ax
ret

exit:
	mov ax, 4c00h
	INT 21H

	ret

delay:
	push si di
		
	mov si, 06ffh
dec_si:	mov di, 0FFFFh
dec_di:	dec di
	jnz dec_di
	dec si
	jnz dec_si

	pop di si
	ret

blank:
	push ax bx cx dx
	mov al,0h
	mov bl,0h
	mov cx,0h ; CH=0, CL=0
	mov dh, 18h
	mov dl, 4fh
	mov ah,06h

	INT 10H
	pop dx cx bx ax
ret

print_txt:	
	push ax bx cx dx

	mov ax,@data ; set up ds as the segment for data
	mov es,ax ; put this in es
	mov ds,ax

	mov bp,OFFSET text

	mov ah,13h ; function 13 - write string
	mov al,01h ; attrib in bl,move cursor,write mode 
	xor bh,bh ; video page 0

	mov bl,Color
	mov cx,Slength ; length of one Char of string

	mov dh,Row ; row to put string
	mov dl,Col ; column to put string

	int 10h ; call BIOS service
	pop dx cx bx ax
	ret



end start_main
So could someone PLEASE help me getting it bounce around the screen? Any help would be great with this. Thanks, Hauk

Share this post


Link to post
Share on other sites
The only thing I can see is that you are only incrementing your row a col variables. When your text reaches the other side, you need to start decrementing instead. Use another variable to keep track of your direction and then add a check in the main loop to determine if you need to increment or decrement.

Share this post


Link to post
Share on other sites
You want the text to bounce right?
It seems to me that all you need to do is to change the sign on RowTst/ColTst when you detect a collision.
(In my world, RowTst would be called VerticalVelocity and ColTst would be HorizontalVelocity)

...
back:
call blank
call print_txt
add Col, ColTst ; add either 1 or -1 (depending on ColTst's sign)
add Row, RowTst ; add either 1 or -1 (depending on RowTst's sign)

cmp Row, 79
jz change_sign_on_RowTst
cmp Row, 0
jz change_sign_on_RowTst

cmp Col, 24
jz change_sign_on_ColTst
cmp Col, 0
jz change_sign_on_ColTst

call delay
loop back
...


edit: same as jvsstudios suggested but with a little code example :)

Share this post


Link to post
Share on other sites
Please don't forget that the length of the string has to play a part aswell. I think the effect would be spoiled by having the text wrap to the next line like this... Awful isn't it?

+-----------------------+
| |
| |
| H|
|ello |
| |
| |
+-----------------------+

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this