\documentclass[10pt]{book}
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
\usepackage{xepersian}
\settextfont{Persian Modern}
\begin{document}
\begin{LTR}
\begin{lstlisting}
for i = 1:3
	if i >= 5                    % literate programming replacement
		disp('cool');           % comment with some §\mcommentfont\LaTeX in it: $\mcommentfont\pi x^2$§
	end
	[~,ind] = max(vec);
	x_last = x(1,end);
	v(end);
	really really long really really long really really long really really long really really long line % blaaaaaaaa
end
\end{lstlisting}
\end{LTR}
\end{document}