flat assembler
Message board for the users of flat assembler.

flat assembler > DOS > Compare command

Author
Thread Post new topic Reply to topic
gildash2



Joined: 30 Oct 2004
Posts: 3
ok, hello all, i am new to the assembler programming world and have recently created the script below. the problem with it though is i wrote a peice of code ,that is bolded, to compare the text in [bx] to '|' and to subtract 2 from the bx value (therefore moving the character back on the screen 2 places, not allowing it to pass the '|') how ever, when it compares to see if the values are correct and then subtract fromt he bx value, it is either not comparing properly or im doing something wrong with the subtraction code. please help me:
Code:
#make_COM#

; COM file is loaded at CS:0100h
ORG 100h

MOV AX, 0B800H
MOV DS, AX
MOV BX, 42
MOV CX, 10
MOV [BX], 'x'
MOV [BX+1], 1
MOV [40], '+',5
MAIN:
MOV AH,00H
INT 16H

CMP AH, 4BH
JE ML
CMP AH, 4DH
JE MR
CMP AH, 50H
JE MD
CMP AH, 48H
JE MU
JNE MAIN



ML: 
MOV [BX], ' '
SUB BX, 2
MOV [BX], 'x'
MOV [BX+1], 1
CMP [BX], '+'   ;code that doesnt work starts here
ADD BX, 2
MOV [BX], 'x'   ;and ends here
JMP MAIN

MR:
MOV [BX], ' '
ADD BX, 2
MOV [BX], 'x'
MOV [BX+1], 1
JMP MAIN

MD:
MOV [BX], ' '
ADD BX, 160D
MOV [BX], 'x'
MOV [BX+1], 1
JMP MAIN 

MU:
MOV [BX], ' '
SUB BX, 160D
MOV [BX], 'x'
MOV [BX+1], 1
JMP MAIN

    
[/b][/code]
Post 30 Oct 2004, 21:54
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Hello,
you meant something like this?
Code:
; COM file is loaded at CS:0100h
ORG 100h

MOV AX, 0B800H
push ds
MOV DS, AX
MOV BX,0
MOV byte [BX],'x'
MOV byte [BX+1],3
MOV byte [40],'+'
MOV byte [41],5
pop ds
MAIN:
MOV AH,$10
INT 16H

push ds
push 0B800H
pop ds

add bx,4
MOV [BX],AL
inc bx
MOV byte [BX],4
sub bx,5

CMP AX,$4BE0
JE ML
CMP AX,$4DE0
JE MR
CMP AX,$50E0
JE MD
CMP AX,$48E0
JE MU
pop ds
CMP AL,27 ; esc
JE escape

JMP MAIN

escape:

int 20h

ML:
add bx,2
MOV byte [BX],'L'
inc bx
MOV byte [BX],$F
sub bx,3
pop ds
JMP MAIN

MR:
MOV byte [BX+2],'R'
MOV byte [BX+3],$F
pop ds
JMP MAIN

MD:
MOV byte [BX+2],'D'
MOV byte [BX+3],$F
pop ds
JMP MAIN

MU:
MOV byte [BX+2],'U'
MOV byte [BX+3],$F
pop ds
JMP MAIN
    
Post 30 Oct 2004, 23:32
View user's profile Send private message Visit poster's website Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
gildash wrote:

Code:
ML:  
MOV [BX], ' ' 
SUB BX, 2 
MOV [BX], 'x' 
MOV [BX+1], 1 
CMP [BX], '+'   ;code that doesnt work starts here 
ADD BX, 2 
MOV [BX], 'x'   ;and ends here 
JMP MAIN 
    


Well, I see an ADD in the place of SUB...and you are not using the result of CMP. Usually after a CMP you writes a Jcc to do a jump. The subtraction(addition) takes place every time.
Post 30 Oct 2004, 23:37
View user's profile Send private message Reply with quote
gildash2



Joined: 30 Oct 2004
Posts: 3
the code doesnt work in my version of emu, could you perhaps point out what is specifically wrong with my code in that spot? because i had it once work perfectly and the CMP code was extremely familiar. what exactly could i change to make that section of my code work, rather than change the whole thing.
thank you so much for your continueing help
Post 31 Oct 2004, 01:54
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
i have changed your cmp ah, s to cmp ax,
and
MOV AH,00H
INT 16H

to

MOV AH,10H
INT 16H

and bios now returns extended scancodes (word in ax)
so i used to use this function.

what is the task of your code?
what do you mean by emu?
sorry for changing all, but i didn't understand what were you gonna do.
however i'd recommend stosw
and its nicer to use es as segment than ds, what if you start putting variables in video mem?
Post 31 Oct 2004, 09:23
View user's profile Send private message Visit poster's website Reply with quote
gildash2



Joined: 30 Oct 2004
Posts: 3
ok im sorry for not properly explaining this. what i basically am doing here is im having the character '+' move when the up,down,left,right arrows are clicked on the keyboard. that works perfectly as you can see in the code. now, the thing that isnt working which i want to work is that when the location of bx ([bx]) hits or is equal to character '|' then i want it to move back 2 spaces, as if the character hit a wall and cannot pass. '|' is supposed to act as a barrier or a wall in a game that the character cannot pass. understand? what i have written in the code makes sense but is for some reason not working. it does this:
CMP [BX], '|' ;compares the position of BX to that character
ADD BX, 2 ;basically if the comparison shows that it is equal, then the position in bx is subtracted by two, and moves the character back
however, this is not working, im assuming that the code to fix this, or even do this task is simple, because i had done it before in almost the exact format. everything except the barrier code works.
thank you again for your continueing help
Post 31 Oct 2004, 12:03
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Here you are:
Code:
; COM file is loaded at CS:0100h
barrier1=178
barrier2=177
;barrier2=176
ORG 100h

push es
push $B800
pop es

call cursoroff

MOV word [ES:884],4 shl 8+barrier1
MOV word [ES:876],4 shl 8+barrier1
MOV word [ES:878+160],4 shl 8+barrier2
MOV word [ES:880+160],4 shl 8+barrier2
MOV word [ES:882+160],4 shl 8+barrier2

MOV BX,880
MOV word [ES:BX],3 shl 8+'+'

MAIN:
MOV AH,$10
INT 16H

CMP AX,$4BE0
JE ML
CMP AX,$4DE0
JE MR
CMP AX,$50E0
JE MD
CMP AX,$48E0
JE MU
CMP AL,27 ; esc
JE escape

JMP MAIN

escape:

call cursoron

pop es

int 20h ; exit

ML:
mov ax,bx
mov cl,160
div cl
cmp ah,2
jb .skip

cmp byte [ES:BX-2],barrier1
je .skip
cmp byte [ES:BX-2],barrier2
je .skip

MOV word [ES:BX],3 shl 8+' '
sub bx,2
MOV word [ES:BX],3 shl 8+'+'
.skip:
JMP MAIN

MR:
mov ax,bx
mov cl,160
div cl
cmp ah,158
jae .skip

cmp byte [ES:BX+2],barrier1
je .skip
cmp byte [ES:BX+2],barrier2
je .skip

MOV word [ES:BX],3 shl 8+' '
add bx,2
MOV word [ES:BX],3 shl 8+'+'
.skip:
JMP MAIN

MD:
mov ax,bx
mov cl,160
div cl
cmp al,24
jae .skip

cmp byte [ES:BX+160],barrier1
je .skip
cmp byte [ES:BX+160],barrier2
je .skip

MOV word [ES:BX],3 shl 8+' '
add bx,160
MOV word [ES:BX],3 shl 8+'+'
.skip:
JMP MAIN

MU:
mov ax,bx
mov cl,160
div cl
cmp al,1
jb .skip

cmp byte [ES:BX-160],barrier1
je .skip
cmp byte [ES:BX-160],barrier2
je .skip

MOV word [ES:BX],3 shl 8+' '
sub bx,160
MOV word [ES:BX],3 shl 8+'+'
.skip:
JMP MAIN

cursoron:  ;  Turns CURSOR ON.
mov ah,1
 mov cx,0x0607
 int 10h
ret

cursoroff: ;  Turns CURSOR OFF.
mov ah,1
 mov cx,0x1400
 int 10h
ret

cursorhidden: ;  Returns 1 if cursorhidden, 0 otherwise.
  mov ah,0x03
   int 10h
   xor al,al
   cmp ch,$20
   jne .skip
   mov al,1
   .skip:
ret
    
Post 02 Nov 2004, 15:57
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.