How do I calculate moles from the given litres and mass of the substance (in grams)?

the molecular mass in grams is the mass of mole.

For example, since C has mass 12 amu and O has mass 16 amu, one mole of CO2 has mass of 12+2*16 = 44g

1M solution is 1 mole/1 liter