Just remember one thing when it comes to these problems: "perpendicular lines have negative reciprocal slopes." That's all you need, if you know how to find the equation of a line.
Your first example: There's a line L passing through (0,0) and perpendicular to y=x. The slope of the line y = x is 1. So if we take the negative reciprocal of 1, we have -1/1, or -1. (If it had been 2, for example, the slope would have been -1/2.) Now that you know the slope of the perpendicular line is -1, use the point (0,0) to determine the line's equation is y = -x.
Your second example. I'll assume your question is to determine the equation of the line, L, that passes through (4,0) and is perpendicular to the line that passes through (-3,1) and (2,6). Use (-3,1) and (2,6) to find the slope of the the line (you don't actually have to find the equation of that line, but it would not hurt if you did). The slope of that line turns out to be 1. Thus any perpendicular line will have a slope that is the negative reciprocal of 1, or -1/1 = -1. Now use the slope of the perpendicular line and the point (4,0) to find that the equation is y = -x + 4.
If you need more help, please clarify where you are in the process and what's giving you trouble. I'd be more than happy to continue to assist.