Problems with CMP and JZ

Posts 13 of 3 · Page 1 of 1
Problems with CMP and JZ
So far I've learned some assembly, and i've tried using cmp and jz as a means of somewhat if statements. I just started learning so I don't know much complex stuff, but here is the code

The problem is, in my POLLING section, only The ESC does what it's supposed to do, close it. Any other key will do the same thing, draw a pixel up. So I'm guessing it's jumping straight to UP


Code:
;simple drawing program using bios and dos interrupts
;ASCII codes, using the numpad
;Up(8)		56
;Down(2)	50
;Left(4)	52
;Right(6) 	54
;ESC 		27
	org 100h
INIT:
	mov ah, 00	;to set video mode
	mov al, 13	;graphics mode 320x200 256 color vga
	int 10h		;change mode

	mov bh, 00	;change video mode
	mov cx, 160	;set x	
	mov dx, 100	;set y -should be middle of screen..hopefully
POLLING:
	mov ah, 08	;to get input without echo, return stored in al
	int 21h		;get the input

	cmp al, 56	;is the return value up?
	jz UP		;if so jump to UP

	cmp al, 50	;is the return value down?
	jz DOWN		;if so jump to DOWN
	
	cmp al, 52	;is the return value left?
	jz LEFT		;if so jump to LEFT
	
	cmp al, 54	;is the return value right?
	jz RIGHT	;if so jump to RIGHT
	cmp al, 27	;is the return value esc?
	jz EXIT
UP:
	dec dx		;decrement dx, the Y axis..The lower X is higher on the screen 
	jmp DRAW	;jump to DRAW ^^ at least i'm pretty sure it is.
DOWN:
	inc dx		;increment dx, the Y axis
	jmp DRAW	
LEFT:
	dec cx		;decrement cx, the X axis
	jmp DRAW
RIGHT:
	inc cx		;increment cx, the X axis
	jmp DRAW
DRAW:
	mov ah, 0ch	;for drawing pixel
	mov al, 0Fh	;color
	int 10h		;draw pixel. bh(page) cx, dx(axes) are already set
	jmp POLLING	;go back to get more presses
EXIT:	
	mov ah, 00	;to set video mode
	mov al, 03	;80x25 16 color text mode
	int 10h		;return to video mode for dos
	int 20h		;terminate
Quote Originally Posted by Auxilium View Post
So far I've learned some assembly, and i've tried using cmp and jz as a means of somewhat if statements. I just started learning so I don't know much complex stuff, but here is the code

The problem is, in my POLLING section, only The ESC does what it's supposed to do, close it. Any other key will do the same thing, draw a pixel up. So I'm guessing it's jumping straight to UP
When something doesn't work the first thing to assume is everything is wrong. Let's begin:

Code:
;simple drawing program using bios and dos interrupts
;ASCII codes, using the numpad
;Up(8)		56
;Down(2)	50
;Left(4)	52
;Right(6) 	54
;ESC 		27
	org 100h
INIT:
	mov ah, 00	;to set video mode
	mov al, 13	;graphics mode 320x200 256 color vga
	int 10h		;change mode
Will this do what you say? let's see...
nope. 13 =/= 13h what mode you set its actually...
Quote Originally Posted by http://www.ctyme.com/intr/rb-0069.htm#Table10
0Dh = G 40x25 8x8 320x200 16 8 A000 EGA,VGA
What you want is...ref.ref
13h = G 40x25 8x8 320x200 256/256K . A000 VGA,MCGA,ATI VIP
since you are using a different mode with a 16 bit greyscale instead of 256 bit color its hard to predict what will happen, but lets continue...


EDIT: well i'd like to continue, but all my links are no longer in service so I will need some references to continue, since i don't know how to do this myself. But we need to figure this out next.

Code:
	mov bh, 00	;change video mode
	mov cx, 160	;set x	
	mov dx, 100	;set y -should be middle of screen..hopefully
POLLING:
	mov ah, 08	;to get input without echo, return stored in al
	int 21h		;get the input
The code after looks solid.
Code:
	cmp al, 56	;is the return value up?
	jz UP		;if so jump to UP

	cmp al, 50	;is the return value down?
	jz DOWN		;if so jump to DOWN
	
	cmp al, 52	;is the return value left?
	jz LEFT		;if so jump to LEFT
	
	cmp al, 54	;is the return value right?
	jz RIGHT	;if so jump to RIGHT
	cmp al, 27	;is the return value esc?
	jz EXIT
UP:
	dec dx		;decrement dx, the Y axis..The lower X is higher on the screen 
	jmp DRAW	;jump to DRAW ^^ at least i'm pretty sure it is.
DOWN:
	inc dx		;increment dx, the Y axis
	jmp DRAW	
LEFT:
	dec cx		;decrement cx, the X axis
	jmp DRAW
RIGHT:
	inc cx		;increment cx, the X axis
	jmp DRAW
I'm unsure about this either.
Code:
DRAW:
	mov ah, 0ch	;for drawing pixel
	mov al, 0Fh	;color
	int 10h		;draw pixel. bh(page) cx, dx(axes) are already set
	jmp POLLING	;go back to get more presses
EXIT:	
	mov ah, 00	;to set video mode
	mov al, 03	;80x25 16 color text mode
	int 10h		;return to video mode for dos
	int 20h		;terminate
Show me the resource you are using and we can work through this together.
Alright, thanks for the help.
/solved

I rewrote my code to use the WASD keys for movement, and it works now.
I'm guessing if you press any other key it will just go through the code till it reaches UP, then it will jump to drawing it.
I tried using the arrow keys, but I guess I got the codes wrong.
Here's my new code, everything works as planned, and exits successfully.
Code:
	org 100h
START:
	mov ah, 00	;to set up the video mode
	mov al, 13h	;320x200 256 Color VGA mode
	mov bh, 00	;video page
	int 10h		;bios int to change video mode
AXIS:
	mov cx, 160	;X Axis
	mov dx, 100	;Y Axis
POLL:
	mov ah, 08	;to get keypress w/o echo
	int 21h		;get press
			;USING WASD FOR DIRECTION
	cmp al, 119	;UP 
	jz UP
	cmp al, 115	;DOWN
	jz DOWN
	cmp al, 97	;LEFT
	jz LEFT
	cmp al, 100	;RIGHT
	jz RIGHT
	cmp al, 27	;ESC
	jz ESC
UP:
	dec dx		;make pixel go up
	jmp PIXEL
DOWN:
	inc dx		;make pixel go down
	jmp PIXEL
LEFT:
	dec cx		;make pixel go left
	jmp PIXEL
RIGHT:
	inc cx		;make pixel go right
	jmp PIXEL
PIXEL:
	mov ah, 0ch	;write pixel mode
	mov al, 0Fh	;color, white
	int 10h		;draw pixel, bh, dx, cx already set.
	jmp POLL	;get another press
ESC:
	mov ah, 00	;same as in START
	mov al, 03         ;80x25 16 color, normal mode for DOS
	int 10h
	int 20h		;terminate
Posts 13 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?