abkds
abkds

Reputation: 1794

why clear the direction flag

.set PROT_MODE_CSEG, 0x8         # kernel code segment selector
.set PROT_MODE_DSEG, 0x10        # kernel data segment selector
.set CR0_PE_ON,      0x1         # protected mode enable flag

.globl start
start:
  .code16                     # Assemble for 16-bit mode
  cli                         # Disable interrupts
  cld                         # clear direction flag -> String operations increment

  # Set up the important data segment registers (DS, ES, SS).
  xorw    %ax,%ax             # Segment number zero
  movw    %ax,%ds             # -> Data Segment
  movw    %ax,%es             # -> Extra Segment
  movw    %ax,%ss             # -> Stack Segment

This is the starting part of the bootloader program of mit 6.828 course . I wanted to know why do we need to clear direction flag . I understand what clearing the direction flag does, but what is the need of clearing it ?

Upvotes: 2

Views: 405

Answers (1)

user149341
user149341

Reputation:

If the direction flag happens to be set when the bootloader transfers control to your code, string operations won't work the way you expect. Most well-behaved bootloaders probably won't do this, but it's good practice to be sure.

Upvotes: 3

Related Questions