\documentclass{article}
\usepackage{listings}
\usepackage{minted}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text

text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text

text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text

\begin{lstlisting}[escapechar=!, frame=single, float]
!\tikzmark{x0}%
 \tikz[overlay, remember picture]{
  \node [fill=pink] (all) at ([xshift=\textwidth]pic cs:x0) {Device A};
 }!code

code

code

code

code

code

code

code
\end{lstlisting}

\newlength{\lbllength}
\settowidth{\lbllength}{Device A}
\newlength{\lblheight}
\settoheight{\lblheight}{The Label}
\begin{listing}
\tikzmark{x1}\tikz[overlay, remember picture]{\node [fill=pink] (all) at ([xshift=0.99\textwidth-0.5*\lbllength]pic cs:x1) {Device A};}
      \begin{minted}[escapeinside=!!,frame=single]{ruby}
!!5 + 5
6 + 6
7 + 7
8 + 8!!5 + 5
6 + 6
7 + 7
8 + 8!!5 + 5
6 + 6
7 + 7
8 + 8!!5 + 5
6 + 6
7 + 7
8 + 8!!5 + 5
6 + 6
7 + 7
8 + 8!!5 + 5
6 + 6
7 + 7
8 + 8!!5 + 5
6 + 6
7 + 7
8 + 8
7 + 7
8 + 8!!5 + 5
6 + 6
7 + 7
8 + 8!!5 + 5
6 + 6
7 + 7
8 + 8
7 + 7
8 + 8!!5 + 5
6 + 6
7 + 7
8 + 8!!5 + 5
6 + 6
7 + 7
8 + 8
    \end{minted}
\end{listing}

\end{document}