Help Needed: Understand Assembly Program Processing Direction

In summary, an understanding of assembly program processing direction is crucial for efficient programming. Assembly programs are processed in a linear fashion, with instructions being executed one after the other in the order they are written. This means that careful attention must be paid to the order in which instructions are placed, as well as any potential branching or looping that may occur. Additionally, understanding the direction of data flow and memory usage in assembly programs is essential for successful program execution. By considering these factors, programmers can ensure that their assembly programs are optimized for speed and accuracy.
  • #1
duynguyenvan
4
0
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:
Physics news on Phys.org
  • #2
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
mgb_phys said:
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.

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
mgb_phys said:
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.

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

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
Upon further review, I suspect a problem. OP, what do you mean by this:

xor cx,cx

That wouldn't seem to do anything.
 
Last edited:
  • #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 !
 
  • #8
Quiz question -- what would be an easier way to clean up the cx register?
 
  • #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).
 
  • #10
genneth said:
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).

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
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
 
  • #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, ...
 
  • #13
ax,dx,al etc? Definitely Intel x86. And int 21h seals it as DOS.
 

FAQ: Help Needed: Understand Assembly Program Processing Direction

What is an assembly program?

An assembly program is a low-level programming language that is used to directly communicate with the computer's hardware. It consists of instructions written in mnemonic codes that correspond to machine code instructions, making it easier for humans to read and understand.

How does an assembly program process instructions?

An assembly program is processed by an assembler, which translates the mnemonic codes into machine code instructions that the computer can understand. These instructions are then executed by the computer's processor in a specific order.

What is meant by "processing direction" in an assembly program?

The processing direction in an assembly program refers to the sequential order in which the instructions are executed. The processor reads and executes the instructions one by one, following the flow of the program, until it reaches the end or a specific condition is met.

How can I understand the processing direction in an assembly program?

To understand the processing direction in an assembly program, it is important to familiarize yourself with the different instructions and their functions, as well as the flow control structures used in the program. It is also helpful to practice reading and tracing the program's execution step by step.

Are there different processing directions in an assembly program?

Yes, there can be different processing directions in an assembly program depending on the program's logic and flow control structures used. For example, a program may have a linear processing direction with instructions executed sequentially, or it may have branching structures that alter the program's flow.

Similar threads

Replies
1
Views
2K
Replies
9
Views
3K
Replies
4
Views
2K
Replies
4
Views
2K
Replies
4
Views
10K
Back
Top