The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: HATEM on September 28, 2006, 12:37:03 PM

Title: please i need your help
Post by: HATEM on September 28, 2006, 12:37:03 PM
hello
look a this program and tell me where is the error  :'(

data     segment 
pass     db    'masm32'
good     db     'OK$'
flt      db     'Sorry$'
namepar  label    byte 
maxlen   db       30 
actlen   db       ? 
namefld  db       30 dup(' ') 
data     ends 
code     segment 
main     proc     far 
         assume   ds:data,cs:code
         mov      ax,data
         mov      ds,ax
         mov      ah,0ah
         lea      dx,namepar
         int      21h
         lea      si,namefld
         lea      di,pass
         mov      cx,6
tour:  mov      dl,[si]
         mov      dh,[di]
         cmp      dh,dl
         jne      xx
         loop     tour
         mov      ah,2h
         lea      dx,good
         int      21h
         jmp      sort
xx:      mov      ah,2h
         lea      dx,flt
         int      21h
sort:    mov      ah,4ch 
         int      21h 
main         endp 
code         ends 
             end         main   

I wan to the program print OK when the user input MASM32 and Sorry if he input different name
Title: Re: please i need your help
Post by: japheth on September 28, 2006, 01:20:15 PM
> look a this program and tell me where is the error

Is there something to win? :)


tour:  mov      dl,[si]
         mov      dh,[di]
         cmp      dh,dl
         jne      xx           ;ok so far, but now you will have to increment si and di
         loop     tour



         mov      ah,2h     ;for a string output ah should be 9 instead of 2
         lea      dx,good
         int      21h

Title: Re: please i need your help
Post by: HATEM on September 28, 2006, 05:29:42 PM
tank you  :U but it still don't print 'OK' where is the error
data     segment 
pass     db    'masm'
good     db     'OK$'
flt      db     'Sorry$'
namepar  label    byte 
maxlen   db       30 
actlen   db       ? 
namefld  db       30 dup(' ') 
data     ends 
code     segment 
main     proc     far 
         assume   ds:data,cs:code
         mov      ax,data
         mov      ds,ax
         mov      ah,0ah
         lea      dx,namepar
         int      21h
         lea      si,namefld
         lea      di,pass
         mov      cx,4
tour:    mov      dl,[si]
         mov      dh,[di]
         cmp      dh,dl
         inc      si
         inc      di
         jne      xx
         loop     tour
         mov      ah,9h
         lea      dx,good
         int      21h
         jmp      sort
xx:      mov      ah,9h
         lea      dx,flt
         int      21h
sort:    mov      ah,4ch 
         int      21h 
main         endp 
code         ends 
             end         main
Title: Re: please i need your help
Post by: P1 on September 28, 2006, 06:31:23 PM
INC - Increment
        Usage:  INC     dest
        Modifies flags: AF OF PF SF ZF
        Adds one to destination unsigned binary operand.
                                 Clocks                 Size
        Operands         808x  286   386   486          Bytes
        reg8              3     2     2     1             2
        reg16             3     2     2     1             1

        reg32             3     2     2     1             1
        mem            15+EA    7     6     3            2-4  (W88=23+EA)

        FE /0 INC r/m8 Increment r/m byte by 1
        FF /0 INC r/m16 Increment r/m word by 1
        FF /0 INC r/m32 Increment r/m doubleword by 1

        40+ rw INC r16 Increment word register by 1
        40+ rd INC r32 Increment doubleword register by 1


Regards,  P1  :8)
Title: Re: please i need your help
Post by: ninjarider on September 28, 2006, 09:53:23 PM
2 things. your incrementing both registers at the same time. there is one that that should not be incremented. and second. the location of your inc's
Title: Re: please i need your help
Post by: HATEM on September 28, 2006, 10:50:36 PM
hello
idon't understant because i am a beginer in assembly can you explain it more please  :red
Title: Re: please i need your help
Post by: P1 on September 28, 2006, 11:09:25 PM
The inc instruction is modifying the flags so the cmp instruction is being ignored, when you get to the jne instruction.

Something to look at:
CMPS - Compare String (Byte, Word or Doubleword)
        Usage:  CMPS    dest,src
                CMPSB
                CMPSW
                CMPSD   (386+)
        Modifies flags: AF CF OF PF SF ZF
        Subtracts destination value from source without saving results.
        Updates flags based on the subtraction and  the index registers
        (E)SI and (E)DI are incremented or decremented depending on the
        state of the Direction Flag.  CMPSB inc/decrements the index

        registers by 1, CMPSW inc/decrements by 2, while CMPSD increments
        or decrements by 4.  The REP prefixes can be used to process
        entire data items.
                                 Clocks                 Size
        Operands         808x  286   386   486          Bytes
        dest,src          22    8     10    8             1  (W88=30)

        A6 CMPS m8, m8
        A7 CMPS m16, m16
        A7 CMPS m32, m32
        A6 CMPSB
        A7 CMPSW
        A7 CMPSD


Please study the opcodes.  Or at least check out "The Art of Assembly", to do some catch up learning.

Regards,  P1  :8)
Title: Re: please i need your help
Post by: HATEM on September 28, 2006, 11:34:02 PM
thank you very much for your help P1 but do you mean i replase one of the  incrementing after cmp or what  :eek
Title: Re: please i need your help
Post by: P1 on September 28, 2006, 11:48:50 PM
HATEM,

You need to invest more time into learning what your doing with the opcodes.  Otherwise pick a different class for school.

To 'Fix' your code as is:
Move the line "jne xx" to after "cmp dh,dl"

Regards,  P1  :8)

Title: Re: please i need your help
Post by: HATEM on September 29, 2006, 12:21:28 AM
forgive me for my questions now it work but still there is an other error look  when print ok it still ms apear near Ok  :(
Title: Re: please i need your help
Post by: PBrennick on September 29, 2006, 02:45:59 PM
HATEM,
I am unsure if I understand your last message but from examining your code, if the OK message is printed then the next place execution goes to is SORT which tells the program to exit.  So nothing will happen after the OK message is printed.

Paul
Title: Re: please i need your help
Post by: ninjarider on September 30, 2006, 01:51:18 AM
if you could repast your code and the results that you are getting.
Title: Re: please i need your help
Post by: japheth on September 30, 2006, 05:53:22 AM

@Paul and ninjarider

you possibly need a bit more phantasy to be able to understand what an absolute newbie might confuse:

1. the user enters "masm" and presses enter -> curser will be at the first "m"
2. hatem's little app displays "OK", on the screen is now "OKsm"
3. program exits, command.com displays a newline


Title: Re: please i need your help
Post by: ninjarider on September 30, 2006, 05:14:28 PM
so all he needs to do is display chr 13 and chr 10. japhet thnx for the insight. when i started in assembly i was by no means new to programming. i already had 5 years of vb.