# I need help, pls !

1. Aug 28, 2007

### duynguyenvan

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?

Regards,
Duy.

Last edited: Aug 28, 2007
2. Aug 28, 2007

### mgb_phys

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.

3. Aug 28, 2007

### 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.

4. Aug 28, 2007

### duynguyenvan

Dear all,
I'm so sorry for that, i just copied and pasted from my Email (contains the signature) directly into the post ...

5. Aug 29, 2007

### 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.

6. Aug 29, 2007

### 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
7. Aug 29, 2007

### duynguyenvan

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 !

8. Aug 29, 2007

### Staff: Mentor

Quiz question -- what would be an easier way to clean up the cx register?

9. Aug 29, 2007

### genneth

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).

10. Aug 29, 2007

### 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....

11. Sep 2, 2007

### duynguyenvan

>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

12. Sep 5, 2007

### DefaultName

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, ...

13. Sep 5, 2007

### Dick

ax,dx,al etc? Definitely Intel x86. And int 21h seals it as DOS.