News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

please i need your help

Started by HATEM, September 28, 2006, 12:37:03 PM

Previous topic - Next topic

HATEM

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

japheth

> 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


HATEM

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

P1

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)

ninjarider

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

HATEM

hello
idon't understant because i am a beginer in assembly can you explain it more please  :red

P1

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)

HATEM

thank you very much for your help P1 but do you mean i replase one of the  incrementing after cmp or what  :eek

P1

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)


HATEM

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  :(

PBrennick

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
The GeneSys Project is available from:
The Repository or My crappy website

ninjarider

if you could repast your code and the results that you are getting.

japheth


@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



ninjarider

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.