Direction of stepper

I have a code for stepper motor.
I am using stepper.move() for rotation.

 int motoruDirPin = 1;
int motoruStepPin = 2;
AccelStepper stepperu(1, motoruStepPin, motoruDirPin);

When I'm connecting dir and pul pins to 1 and 2, the motor is rotating in the same direction for both positive and negative values in stepper.move()

 int motoruDirPin = 3;
int motoruStepPin = 5;
AccelStepper stepperu(1, motoruStepPin, motoruDirPin);

When I'm connecting these pins to PWM, the direction changes for stepper.move(steps) and stepper.move(-steps).

Why is that?

What Arduino are you using?

Pins 0 and 1 are used for Serial communication on an Uno and Mega and it is best not to use them for anything else.

This does not make sense without seeing your complete program.

When I'm connecting these pins to PWM

If you are using the pins for your stepper why would you be also using them for anlaogWrite()

...R
Stepper Motor Basics
Simple Stepper Code

Try connecting your stepper driver to two non-PWM pins that are NOT the hardware serial pins, and see what the stepper does with a positive, and a negative, number of steps.