flat assembler
Message board for the users of flat assembler.

Index > Main > Why CLD not used in display_string?

Author
Thread Post new topic Reply to topic
alkap



Joined: 18 Feb 2015
Posts: 44
Location: Dnipro, Ukraine
alkap 05 Feb 2016, 18:36
I have noticed that the 'display_string' function, defined in 'system.inc' does not use the CLD instruction. The said instruction does not seem to be used in 'fasm.asm' either.
Is that because fasm clears the direction flag implicitly in some way, or is there some other explanation?
Thanks.
Post 05 Feb 2016, 18:36
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8358
Location: Kraków, Poland
Tomasz Grysztar 05 Feb 2016, 19:57
fasm relies on the convention that DF flag remains cleared by default. So every time fasm changes the direction flag to 1 for some reason (with STD), it clears it back with CLD immediately after.

In DOS interface (SOURCE/DOS/FASM.ASM) you may notice that there is a single CLD during the startup and then DF remains 0 for the entire life of program. In modern systems the DF is already by convention cleared as default, so Windows/Linux versions do not even have that initial CLD. You may find this mention in the Anger Fog's document on calling conventions:
Anger Fog wrote:
The rules for the direction flag is the same in all systems. The direction flag is cleared by default. If the direction flag is set, then it must be cleared again before any call or return.
Post 05 Feb 2016, 19:57
View user's profile Send private message Visit poster's website Reply with quote
alkap



Joined: 18 Feb 2015
Posts: 44
Location: Dnipro, Ukraine
alkap 05 Feb 2016, 20:04
Thanks very much, Tomasz, for a prompt reply. I use fasm on Linux. The explanation you have given makes perfect sense.
Post 05 Feb 2016, 20:04
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.