Results 1 to 3 of 3
  1. #1
    Auxilium's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,518
    Reputation
    445
    Thanks
    609
    My Mood
    Happy

    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
    Last edited by Auxilium; 10-01-2012 at 06:58 PM.

  2. #2
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Virtual Void 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 https://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.
    Last edited by why06; 10-01-2012 at 10:24 PM.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  3. The Following User Says Thank You to why06 For This Useful Post:

    Auxilium (10-02-2012)

  4. #3
    Auxilium's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,518
    Reputation
    445
    Thanks
    609
    My Mood
    Happy
    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
    Last edited by Auxilium; 10-02-2012 at 05:05 AM.

Similar Threads

  1. Problems with alterIWnet and basic hax 3.1.0
    By Psychros in forum Call of Duty Modern Warfare 2 Help
    Replies: 8
    Last Post: 07-16-2010, 07:47 AM
  2. [Help] Problem with wallhack and my Golden AK
    By Wyo in forum CrossFire Hacks & Cheats
    Replies: 14
    Last Post: 02-28-2010, 09:10 AM
  3. [Help] Problem with FRAPS and HYPERCAM
    By BUSTER123 in forum CrossFire Hacks & Cheats
    Replies: 7
    Last Post: 12-23-2009, 10:13 AM
  4. Problem With Xfire and Warrock
    By lagginswag in forum General Hacking
    Replies: 1
    Last Post: 09-12-2009, 12:22 PM
  5. Solve Problems with Vista and hacks
    By knappy in forum Combat Arms Hacks & Cheats
    Replies: 5
    Last Post: 08-11-2008, 06:26 PM