In this paper, we describe a gait generation method for the crawling motion of a legged robot using Normalized Energy Stability Margin (NESM). The crawling motion is a method of locomotion that, since the robot is very close to a state of falling, its leg and torso are grounded alternately in order to enable the robot to move with a low center of gravity. It has the benefit of decreasing the impact experienced by the robot and reduces the risk of becoming damaged if it falls over. However, during the phase where only the robot's torso is in contact with the ground, the size of robot's support area is smaller than the case when its legs are in contact with the ground. This decrease in support area may cause the robot to fall or tip over sideways in the direction where the edge of robot's cuboid torso is providing the most support on an inclined surface. As a result, the robot's feet may collide with the road's surface when its legs are moving forward and prevent the robot from performing its crawling motion. To deal with this problem, we propose a method of gait generation for the crawling motion based on a stability criteria. Depending on the stability criteria, this method involves the selection of a stance, with which it lifts its torso and a way of controlling the landing height of the robot's feet depending on the unevenness of the surface of the road. In experiments, it has been confirmed that stability was improved when the four-limbed robot performed the crawling motion using the proposed method on an inclined road surface.