flat assembler
Message board for the users of flat assembler.

Index > DOS > Problems comparing strings or characters

Author
Thread Post new topic Reply to topic
maxrio



Joined: 14 Feb 2011
Posts: 1
maxrio
Hi everyone!

I'm making a small program that should display a message if var1 is the same word/character that var2 has but it doesnt seem to work.

Code:
MYStack Segment stack 'stack'
        dw 256 dup(?)
MYStack EndS

Data Segment
  var1    db      'A'
       var2    db      'A'
        der     db      "NOT EQUAL$"
        dor     db      "EQUAL$"
Data EndS
Code Segment
        assume CS:Code, SS:MYStack, DS:Data
       _yes:       mov ah, 09h
         lea dx, dor
         int 21h
             jmp stop

        start:  mov ax, Data
                mov DS, ax
                mov ax, MYStack
                mov SS, ax                 
            cld
         lea si, var1
                lea di, var2
                mov cx, 1
           repe cmpsb
          jz  _yes
                mov ah, 09h
                lea dx, der
                int 21h

        stop:    mov ax, 4c00h
                int 21h
Code EndS
end start
    



Also, i'm trying to compare an argument from the command line to a variable if anyone has any ideas about that i would thankyou very much but for now im trying to figure the above code out. Thanks!
Post 14 Feb 2011, 03:51
View user's profile Send private message Reply with quote
b1528932



Joined: 21 May 2010
Posts: 287
b1528932
Quote:
strings or characters

No, not characters. Bytes. String of bytes.


you do not initialize sp, any reason? Why you touch ss anyway, wont dos init ss:sp for you anyway?

You have to assemble ur program at 0x100, you know? Its the address dos will load it. 0-0x100 contain PSP.



about cmd line, read http://en.wikipedia.org/wiki/Program_Segment_Prefix
Post 14 Feb 2011, 08:56
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:
I'm making a small program


I found a small program would be more true ? Laughing

Quote:
it doesnt seem to work


Because it is MA$M code, not FASM. Please study the FAQ on the thread top.

Code:
; FASM code - testing REPE CMPSB instruction
; Untested, at your own RISK !!!

format binary as "COM"
org $0100
use16

                cld 
                mov dx, xyes 
                mov si, var1 
                mov di, var2 
                mov cx, 1
                repe cmpsb 
                jz  qqyes 
                mov dx, xnot 
qqyes:          mov ah, 9
                int $21
                mov ax, $4C00  ; Terminate COM or MZ EXE
                int $21
                ;------

        var1:   db      'A' 
        var2:   db      'A' 
        xnot:   db      "NOT EQUAL$" 
        xyes:   db      "YES EQUAL$" 
    


Simple, isn't it ?

> about cmd line, read http://en.wikipedia.org/wiki/Program_Segment_Prefix

Look at address $80 (relative to PSP begin, and in DOS COM (not in DOS MZ EXE) to CS:ZERO) for ("length"+1) and $82 start of the string (max 125 char's).
Post 14 Feb 2011, 08:58
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.