1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

I need help, pls !

  1. Aug 28, 2007 #1
    I need help, pls !!!!!!!!!!!!!!!!!!!!!!!!!!

    Hello,
    Could you pls help me answer this question:
    - Please take a look at my small Assembly program that reads a tring from keyboard, then displays all the characters that are not uper-case letters in reverse order:

    .model small
    .stack 100
    .data
    tb1 db 'Pls enter a string, enter to finish $'
    tb2 db 10,13,'The characters that are not uper-case : $'
    xau db 80 dup(?)
    .code
    Main proc
    mov ax,@data
    mov ds, ax
    mov es, ax
    mov ah,9
    lea dx,tb1
    int 21h
    xor cx,cx
    lea di,xau
    nhap: mov ah,1
    int 21h
    cmp al,13
    je thoi
    cmp al,'A'
    jb dung
    cmp al,'Z'
    ja dung
    jmp nhap
    dung: stosb
    inc cx
    jmp nhap
    thoi: mov ah,9
    lea dx,tb2
    int 21h
    dec di
    mov si,di
    std
    mov ah,2
    quay: lodsb
    mov dl,al
    int 21h
    loop quay
    mov ah,4ch
    int 21h
    Main endp
    End main

    The code above runs very well, even though i did not use the Clear Direction Flag (cld) instruction after the instruction in red (lea di,xau)
    The string processing is still in forward direction.
    The question is that: Why?

    I appreciate your help.

    Regards,
    Duy.
     
    Last edited: Aug 28, 2007
  2. jcsd
  3. Aug 28, 2007 #2

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    Don't multiple post this especially not as a reply on other peoples threads.
    And you aren't doing IBM any favours by advertising yourself as the project leader.
     
  4. Aug 28, 2007 #3

    berkeman

    User Avatar

    Staff: Mentor

    I deleted the cross-posts in other people's threads. That was a lot of work.

    duynguyenvan, welcome to the PF, but please do not cross-post. You should get the help you need here in this thread. Thank you.
     
  5. Aug 28, 2007 #4
    Dear all,
    I'm so sorry for that, i just copied and pasted from my Email (contains the signature) directly into the post ...
     
  6. Aug 29, 2007 #5

    berkeman

    User Avatar

    Staff: Mentor

    Okay, no worries. The work's been done to clean it all up, and hopefully you will get some good help on your question here at the PF.
     
  7. Aug 29, 2007 #6

    berkeman

    User Avatar

    Staff: Mentor

    Upon further review, I suspect a problem. OP, what do you mean by this:

    That wouldn't seem to do anything.
     
    Last edited: Aug 29, 2007
  8. Aug 29, 2007 #7
    what do you mean? that is to clean up the cx register, and use the register for counting the number of the characters that are not upper-case letters later.
    By the way, i have not had much experience of doing with Assemply stuffs, that's why i asked you guys the "simple" question ... can you understand and answer my question, berkeman?
    pls mail me to this address: duyngv@us.ibm.com
    if you have time to help me understand about my question, your help will be really appreciated !
     
  9. Aug 29, 2007 #8

    berkeman

    User Avatar

    Staff: Mentor

    Quiz question -- what would be an easier way to clean up the cx register?
     
  10. Aug 29, 2007 #9
    berkeman: unfortunately the OP is correct. That is a much used way to clear a register, rather than moving a zero in. On some architectures the move zero is actually slower, as the xor doesn't need to touch anything apart from one register (no extra circuitry is used).
     
  11. Aug 29, 2007 #10

    berkeman

    User Avatar

    Staff: Mentor

    Thanks for the feedback, genneth. I guess I haven't worked with that variation. I'll go back and clean up some of my comments, and see if I can offer some help on their question....
     
  12. Sep 2, 2007 #11
    I've got the answer, thanks!

    >Could you pls help me answer this question:
    >- Please take a look at my small Assembly program that reads a tring from
    >keyboard, then displays all the characters that are not uper-case letters in
    >reverse order:
    >
    >The code above runs very well, even though i did not use the Clear Direction
    >Flag (cld) instruction after the instruction in red (lea di,xau)
    >The string processing is still in forward direction.
    >The question is that: Why?

    DOS sets up the CLD for you, before starting the program. It's an
    assumption you can make, if you want. I often set or clear it anyway,
    just to be sure. But DOS does prepare a few things before running the
    program.

    Also, your program has a bug. It does NOT check to see if CX is zero
    (nothing was entered) before proceeding. You instead use a LOOP
    instruction at the end, which if CX starts as zero will output 65535
    garbage characters on the screen. This obviously isn't good practice.

    You might consider also dealing with backspacing, in case the user
    wants to edit their line.

    I'm including two files in return that do these things. The longer
    file includes a general template for both .EXE and .COM files. You
    might want to read through it, though perhaps it is too much to wade
    through. The other one attempts to be a fairly close representation
    of what you already wrote, doesn't include much comment, and just gets
    the job done.

    Jon
     
  13. Sep 5, 2007 #12
    Unrelated, but... how do you know what type of microprocessor code this is?

    We learned one in a family from Motorola, but I wouldn't be able to tell off the top of my head what each instruction does, aside from the basic MOV, xor, ...
     
  14. Sep 5, 2007 #13

    Dick

    User Avatar
    Science Advisor
    Homework Helper

    ax,dx,al etc? Definitely Intel x86. And int 21h seals it as DOS.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: I need help, pls !
  1. I need help guys (Replies: 1)

  2. I need help (Replies: 0)

Loading...