From the Super Mario Wiki
Assist Blocks are golden blocks that appear in the Nintendo 3DS games Super Mario 3D Land, New Super Mario Bros. 2 and, on the Wii U game Super Mario 3D World. There are two types of Assist Blocks: one that contains an Invincibility Leaf, and one that contains a P-Wing, each shown with an icon of their respective power-ups. Each block is meant to contain these power-ups which assist the player to reach the end, and they appear near the beginning (or midway) of the stage after losing a certain number of lives in that stage.
The Invincibility Leaf Assist Block only appears after Mario loses five lives in a single stage. Once Mario collects the Invincibility Leaf, he transforms into White Tanooki Mario (Super Mario 3D Land and Super Mario 3D World) or White Raccoon Mario (New Super Mario Bros. 2) and becomes invincible for the entire stage. However in Super Mario 3D Land, Luigi cannot obtain one unless the player, as Mario, skips a world by Warp Zone.
In Super Mario 3D Land, the P-Wing Assist Block appears after Mario loses ten lives in a stage. Using the P-Wing takes Mario all the way to the end of the stage, in front of the Flagpole.
Assist Blocks don't appear in any level of the Special Worlds in Super Mario 3D Land. If Mario beats a level in Super Mario 3D Land and Super Mario 3D World, the Assist Block will not appear in that level. However, in New Super Mario Bros. 2, even if Mario beats the level without unlocking the Assist Block, he can still go back into the level and lose lives until it appears.
If any of the Assist Blocks appear in a stage, the player will be unable to have glittering stars on their save file (The same thing applies to the Super Guide Blocks from New Super Mario Bros. Wii). However, the player can get them back by clearing the stage without using the Assist Block, after which the block will disappear.
Names in Other Languages