diff --git a/MEPA b/MEPA
index 474ac52a6e55412add7b8b8b8faf7f146071cf23..a4b0bcc632e5cdcbf313bf853add55d075acf05c 100644
--- a/MEPA
+++ b/MEPA
@@ -41,11 +41,12 @@ R04: NADA
      CRVI 1,-4
      IMPR
      DMEM 2
+     RTPR 1,2
 R00: NADA 
      AMEM 1
      CRCT 3
      CREN 0,0
-     CHPR R01,-1
+     CHPR R01,0
      IMPR
      CRVL 0,0
      IMPR
diff --git a/compilador b/compilador
index 9ab823f80184abcdeaecd79c98b052f8d40dbdf9..f090175ca12229a9f2b1f8142bdc6ba62b819eb7 100755
Binary files a/compilador and b/compilador differ
diff --git a/compilador.tab.c b/compilador.tab.c
index 807234964a8d8ddadd512cdcd9a592e0d8b82ecc..69108ffa7ebaf889e238b7881df685ba1522e060 100644
--- a/compilador.tab.c
+++ b/compilador.tab.c
@@ -563,8 +563,8 @@ static const yytype_int16 yyrline[] =
 {
        0,    47,    47,    47,    63,    74,    60,    93,    94,    97,
      101,   101,   102,   105,   106,   110,   113,   110,   121,   134,
-     143,   154,   155,   159,   161,   162,   167,   191,   167,   210,
-     234,   238,   210,   246,   247,   245,   255,   258,   259,   263,
+     143,   154,   155,   159,   161,   162,   167,   191,   167,   205,
+     229,   233,   205,   246,   247,   245,   255,   258,   259,   263,
      262,   272,   272,   280,   281,   284,   294,   297,   298,   299,
      302,   303,   306,   307,   308,   309,   310,   311,   314,   314,
      318,   319,   322,   322,   353,   353,   395,   398,   402,   401,
@@ -1639,21 +1639,16 @@ yyreduce:
                char buffer[50];
                desempilha(buffer,proc);
                l_elem = busca(buffer,ts);
-               int n;
-               if(l_elem->categ == PR)
-                  n = l_elem->info.pr.quant;
-               else if (l_elem->categ == FUN)
-                  n = l_elem->info.pr.quant;
-               sprintf(buffer,"RTPR %d,%d",l_elem->nivel,n);
+               sprintf(buffer,"RTPR %d,%d",l_elem->nivel,l_elem->info.pr.quant);
                geraCodigo(NULL,buffer);
                desloc = retira_vs_pf(ts);
                mostra_ts(ts);
             }
-#line 1653 "compilador.tab.c"
+#line 1648 "compilador.tab.c"
     break;
 
   case 29:
-#line 210 "compilador.y"
+#line 205 "compilador.y"
                                   {
              // Insere o funcao na tabela de símbolos
             info_t info;
@@ -1677,22 +1672,27 @@ yyreduce:
             geraCodigo(r_func,buffer);
             mostra_ts(ts);
             }
-#line 1681 "compilador.tab.c"
+#line 1676 "compilador.tab.c"
     break;
 
   case 30:
-#line 234 "compilador.y"
+#line 229 "compilador.y"
                         {
                num_vars = 1;
             }
-#line 1689 "compilador.tab.c"
+#line 1684 "compilador.tab.c"
     break;
 
   case 31:
-#line 238 "compilador.y"
+#line 233 "compilador.y"
             { 
-                // Retorna ao nível léxico anterior e mantém o deslocamento atualizado
-                nivel_lexico -= 1; 
+               char buffer[50];
+               desempilha(buffer,proc);
+               l_elem = busca(buffer,ts);
+               sprintf(buffer,"RTPR %d,%d",l_elem->nivel,l_elem->info.fun.quant);
+               geraCodigo(NULL,buffer);
+               desloc = retira_vs_pf(ts);
+               mostra_ts(ts); 
             }
 #line 1698 "compilador.tab.c"
     break;
diff --git a/compilador.y b/compilador.y
index 805631e52732427b696e0a5e44b9ba90b8f10d7a..644d0049f661eadfcba6fab5a6e0769968185203 100644
--- a/compilador.y
+++ b/compilador.y
@@ -192,12 +192,7 @@ declaracao_procedimento: PROCEDURE IDENT {
                char buffer[50];
                desempilha(buffer,proc);
                l_elem = busca(buffer,ts);
-               int n;
-               if(l_elem->categ == PR)
-                  n = l_elem->info.pr.quant;
-               else if (l_elem->categ == FUN)
-                  n = l_elem->info.pr.quant;
-               sprintf(buffer,"RTPR %d,%d",l_elem->nivel,n);
+               sprintf(buffer,"RTPR %d,%d",l_elem->nivel,l_elem->info.pr.quant);
                geraCodigo(NULL,buffer);
                desloc = retira_vs_pf(ts);
                mostra_ts(ts);
@@ -236,8 +231,13 @@ declaracao_funcao: FUNCTION IDENT {
             } tipo
             PONTO_E_VIRGULA bloco
             { 
-                // Retorna ao nível léxico anterior e mantém o deslocamento atualizado
-                nivel_lexico -= 1; 
+               char buffer[50];
+               desempilha(buffer,proc);
+               l_elem = busca(buffer,ts);
+               sprintf(buffer,"RTPR %d,%d",l_elem->nivel,l_elem->info.fun.quant);
+               geraCodigo(NULL,buffer);
+               desloc = retira_vs_pf(ts);
+               mostra_ts(ts); 
             }
             PONTO_E_VIRGULA
 ;