%--*- latex -*-----------------------------------------------------------------
%$Author: saulius $
%$Date: 2020-06-04 14:58:32 +0300 (Thu, 04 Jun 2020) $ 
%$Revision: 1524 $
%$URL: svn+ssh://saulius-grazulis.lt/home/saulius/svn-repositories/seminarai/2020-verifikacjos-seminarui/slides.tex $
%------------------------------------------------------------------------------

\documentclass[mathserif]{beamer}
\usetheme{Warwick}
\useoutertheme{infolines}
\setbeamertemplate{headline}{} % removes the headline the infolines inserts
%\setbeamertemplate{footline}[frame number]
\renewcommand\familydefault{\rmdefault}
% For XeLaTeX:
% https://tex.stackexchange.com/questions/452151/how-do-i-render-the-word-v%C7%ABlundarkvi%C3%B0a-with-bookman-and-xelatex
% "Use an OpenType clone of Bookman, for instance TeX Gyre Bonum":
\usepackage{fontspec}
\setmainfont{TeX Gyre Bonum}

\usepackage[style=authoryear,maxnames=1,doi=true,url=true,backend=biber]{biblatex}
%\addbibresource{bibliography/citations.bib}
\addbibresource{bibliography/Intel.bib}
\addbibresource{bibliography/AMD.bib}
\addbibresource{bibliography/Jorgensen.bib}
\addbibresource{bibliography/Domas.bib}
\addbibresource{bibliography/Dolan.bib}
\newcommand{\mycite}{\parencite}


\usepackage{colordvi}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{snakes}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{chemfig}
\usepackage{listings}

% https://en.wikibooks.org/wiki/LaTeX/Algorithms
% http://mirror.datacenter.by/pub/mirrors/CTAN/macros/latex/contrib/algorithmicx/algorithmicx.pdf
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{amssymb}

\include{commands}

\newcommand{\RCSid}[1]{\fontsize{7pt}{7pt}\selectfont $#1$ \today}

%%BEGIN LANGUAGE lt
\title{Intel x86 procesorių architektūra}
%%END LANGUAGE lt



\author{Saulius Gražulis}

\date{Vilnius, 2020}

% Define colors as in
% https://venngage.com/blog/color-blind-friendly-palette/ ``Retro''
\definecolor{Bluish}{HTML}{63ACBE}
\definecolor{Magentish}{HTML}{601A4A}
\definecolor{Orangish}{HTML}{EE442F}

\begin{document}

\colorlet{IdentifierColor}{red!40!black}
\colorlet{StringColor}{green!70!black}
\colorlet{KwdColor}{Bluish}
\colorlet{CommentColor}{Orangish}

%------------------------------------------------------------------------------

\begin{frame}
    \titlepage

\input{affiliation_lt}
    
    \begin{center}
      \mbox{}
      \hfill\hfill\hfill
      \includegraphics[height=1.5cm]{images/sp_VU_zenklas.eps}
      \hfill
      \includegraphics[height=1.5cm]{images/2019-05-02_Melynas_MIF-zenklas242x244.png}
      \hfill\hfill\hfill
      \mbox{}
    \end{center}

    \vfill

    %% \tiny
    %% \RCSid{
    %%   $Id: slides.tex 1524 2020-06-04 11:58:32Z saulius $
    %% }
    \begin{flushright}
      \begin{minipage}[c]{0.67\textwidth}
        \tiny\raggedright
        %%BEGIN LANGUAGE lt
        Šį skaidrių rinkinį galima kopijuoti,
        kaip nurodyta Creative Commons
        %%END LANGUAGE lt
        \myhref{http://creativecommons.org/licenses/by-sa/4.0/}{Attribution-ShareAlike
          4.0 International}
licenzijoje
      \end{minipage}
      %%
      \begin{minipage}[c]{1.5cm}
        \myhref{http://creativecommons.org/licenses/by-sa/4.0/}{
          \includegraphics[width=1.5cm]{images/CC-BY-SA.eps}
        }
      \end{minipage}
    \end{flushright}

\end{frame}

%==============================================================================

\begin{frame}
\frametitle{Ką reikia nurodyti apie procesoriaus architektūrą?}

  \begin{center}

    %%BEGIN LANGUAGE lt
    Programuotojui matoma architektūra:
    %%END LANGUAGE lt


    \begin{itemize}
    \item
      \color{gray}

      %%BEGIN LANGUAGE lt
      Registrai, matomi programuotojui
      %%END LANGUAGE lt

    \item

      %%BEGIN LANGUAGE lt
      Atminties adresavimas
      %%END LANGUAGE lt

    \item

      %%BEGIN LANGUAGE lt
      Duomenų formatai
      %%END LANGUAGE lt

    \item
      \color{black}

      %%BEGIN LANGUAGE lt
      Procesoriaus komandos
      %%END LANGUAGE lt

    \item

      %%BEGIN LANGUAGE lt
      Įvestis ir išvestis
      %%END LANGUAGE lt

    \item

      %%BEGIN LANGUAGE lt
      Pertraukimų apdorojimas
      %%END LANGUAGE lt

      
    \end{itemize}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Registrai (x86)}

  \begin{center}
    Intel 8086 CPU
    
    \includegraphics[width=4cm]{drawings/Intel/8086-regs.eps}
  \end{center}
  
  \leftline{\scriptsize\mycite{INTEL1979}}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Registrai (x86\_64)}

  \begin{center}
    \includegraphics[page=36,width=11cm,trim=2cm 13.7cm 2cm 6cm,clip]{images/AMD-dokumentacija/AMD64_Architecture_Programmers_Manual_Vol_1.pdf}
  \end{center}

  \leftline{\scriptsize\mycite{AMD2017}}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Steko veikimas}

  \begin{center}
    \includegraphics[page=54,width=5cm,trim=3cm 16.6cm 10.8cm 8.2cm,clip]{images/AMD-dokumentacija/AMD64_Architecture_Programmers_Manual_Vol_1.pdf}
    \includegraphics[page=54,width=5cm,trim=10.5cm 16.6cm 3cm 8cm,clip]{images/AMD-dokumentacija/AMD64_Architecture_Programmers_Manual_Vol_1.pdf}
  \end{center}
  
  \leftline{\scriptsize\mycite{AMD2017}}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Komandų skaitliukas}

  \begin{center}
    \includegraphics[page=55,width=7cm,trim=6.1cm 18cm 5cm 8.3cm,clip]{images/AMD-dokumentacija/AMD64_Architecture_Programmers_Manual_Vol_1.pdf}
  \end{center}
  
  \leftline{\scriptsize\mycite{AMD2017}}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Registrai, suderinamumo režimai}

  \begin{center}
    \includegraphics[page=59,width=7cm,trim=6.1cm 18cm 5cm 4cm,clip]{images/AMD-dokumentacija/AMD64_Architecture_Programmers_Manual_Vol_1.pdf}
  \end{center}
  
  \leftline{\scriptsize\mycite{AMD2017}}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Registrai}

  \begin{center}
    \includegraphics[page=58,height=7cm,trim=4cm 9cm 4cm 5cm,clip]{images/AMD-dokumentacija/AMD64_Architecture_Programmers_Manual_Vol_1.pdf}
  \end{center}
  
  \leftline{\scriptsize\mycite{AMD2017}}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Segmentinė adresacija}

  %%BEGIN LANGUAGE lt
  Segmento adresas pastumiamas 4-iais bitais ir sudedamas su postūmiu:
  %%END LANGUAGE lt

  \vspace{\baselineskip}
%%   \only<1>{
%%     \begin{center}
%%       \includegraphics[width=3cm]{drawings/Intel/8086-segments.eps}
%%     \end{center}
%%   }
%%  \only<2>{
    \begin{center}
      \includegraphics[width=7cm,page=28,trim=4cm 17cm 4cm 2cmcm,clip]{images/Intel-dokumentacija/Intel_8086_Family_Users_Manual_October_19-INTEL.pdf}
    \end{center}
%%  }

  \mycite{INTEL1979}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Požymių registras}

  \begin{center}
    \includegraphics[page=68,width=11cm,trim=2cm 10.5cm 2cm 11.4cm,clip]{images/AMD-dokumentacija/AMD64_Architecture_Programmers_Manual_Vol_1.pdf}
  \end{center}
  
  \leftline{\scriptsize\mycite{AMD2017}}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Požymiai}

  \begin{itemize}
  \item
\textbf{Perkėlimo požymis (CF)}
  \item
\textbf{Perpildymo požymis (OF)}
  \item
\textbf{Pagalbinio perpildymo požymis (AF)}
  \item
\textbf{Lyginimo požymis (PF)}
  \item
\textbf{Nulio požymis (ZF)}
  \item
\textbf{Ženklo (neigiamo) požymis (SF)}
  \item
\textbf{Krypties požymis (DF)}
  \end{itemize}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Komandų tipai}

  \begin{itemize}
  \item
Duomenų persiuntimo
    
  \item
Duomenų transformacijos komandos
    
  \item
Aritmetinės komandos

  \item
Loginės komandos

  \item
Valdymo komandos

  \end{itemize}

  \rightline{\scriptsize\mycite{Jorgensen2020}}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Išplėtimas nuliais įkeliant 32-jų bitų operandus}


  %%BEGIN LANGUAGE lt
  Kai 32-jų bitų operandai įkeliami į bendros paskirties registrus
  64-ių bitų režime, skaičius išplečiamas nuliais (pav. 3-3, 3-4).
  %%END LANGUAGE lt
  

  \begin{center}
    \includegraphics[page=61,width=11cm,trim=4cm 19.9cm 2cm 4cm,clip]{images/AMD-dokumentacija/AMD64_Architecture_Programmers_Manual_Vol_1.pdf}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Komandų sintaksė}

  \begin{center}
    \includegraphics[page=78,width=8cm,trim=6cm 7cm 6cm 18cm,clip]{images/AMD-dokumentacija/AMD64_Architecture_Programmers_Manual_Vol_1.pdf}
  \end{center}
  
  \leftline{\scriptsize\mycite{AMD2017}}

  {\scriptsize\mywebref{https://en.wikipedia.org/wiki/X86\_instruction\_listings}}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Komandų skaičius}

  \begin{itemize}
  \item

    %%BEGIN LANGUAGE lt
    Apie 100 skirtingų instrukcijų (asemblerio lygyje) \mycite{INTEL1979}
    %%END LANGUAGE lt


  \item

    %%BEGIN LANGUAGE lt
    Bet: pvz., viena \texttt{MOV} instrukcija atitinka 28 skirtingas
    mašinos komandas (operacijų kodus)...
    %%END LANGUAGE lt


    \begin{itemize}
    \item
      %%BEGIN LANGUAGE lt
      ... \texttt{MOV} yra pilna pagal Tiuringą! \mycite{Dolan2013}
      %%END LANGUAGE lt
    \end{itemize}
    
  \item
    %%BEGIN LANGUAGE lt
    Procesoriaus x86\_64 architektūra turi, grubiai tariant, apie 1000
    (ar 3000) komandų, priklausomai nuo to, kaip skaičiuosime...
    %%END LANGUAGE lt
    \footnote{\tiny\mywebref{https://stefanheule.com/blog/how-many-x86-64-instructions-are-there-anyway}}

  \item
    
    %%BEGIN LANGUAGE lt
    Procesoriaus x86\_64 architektūros \textit{komandų erdvė} (1-15 baitų)
    yra $1.3\cdot{}10^{36}$ galimų komandų. Šį skaičių galima sumažinti
    iki aprėpiamo $\approx 10^{8}$ naudojant gudrią paiešką į gylį
    \mycite{Domas2017}
    %%END LANGUAGE lt
    
    
  \end{itemize}

  %% \leftline{\scriptsize Intel 8086 Family User's guide, p.~2-30}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Operandų skaičius}

  \begin{itemize}
  \item
    %%BEGIN LANGUAGE lt
    0 adresų mašinos:
    %%END LANGUAGE lt
    \fbox{\texttt{OPCODE}}

  \item
    %%BEGIN LANGUAGE lt
    1 adreso mašinos:
    %%END LANGUAGE lt
    \fbox{\texttt{OPCODE}}\fbox{\texttt{OPERAND}}

  \item
    %%BEGIN LANGUAGE lt
    2 adresų mašinos:
    %%END LANGUAGE lt
    \fbox{\texttt{OPCODE}}\fbox{\texttt{OP1}}\fbox{\texttt{OP2}}

  \item
    %%BEGIN LANGUAGE lt
    3 adresų mašinos:
    %%END LANGUAGE lt
    \fbox{\texttt{OPCODE}}\fbox{\texttt{OP1}}\fbox{\texttt{OP2}}\fbox{\texttt{OP3}}

  \item
    %%BEGIN LANGUAGE lt
    4 adresų mašinos:
    %%END LANGUAGE lt
    \fbox{\texttt{OPCODE}}\fbox{\texttt{OP1}}\fbox{\texttt{OP2}}\fbox{\texttt{OP3}}\fbox{\texttt{OP4}}

  \end{itemize}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Komandų kodavimas (formatas)}

  %%BEGIN LANGUAGE lt
  Tik vienas operandas gali būti atmintyje!
  %%END LANGUAGE lt
  
  \begin{center}
    \fbox{
    \includegraphics[page=161,width=11cm,trim=2cm 11.5cm 2cm 6cm,clip]{bibliography/PDF/Intel-8086-Family-users-manual.pdf}
    }
  \end{center}
  
  \leftline{\scriptsize Intel 8086 Family User's guide}
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Komandų formatas – 64-ių bitų režimas}

  \begin{center}
    \includegraphics[page=45,height=7cm,trim=3cm 13.3cm 12cm 4.5cm,clip]{images/AMD-dokumentacija/AMD64_Architecture_Programmers_Manual_Vol_3.pdf}
  \end{center}
  
  \leftline{\scriptsize\mycite{AMD2017}, Vol.~3}
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Registrų kodavimas}

  \begin{center}
    \includegraphics[page=162,width=6cm,trim=9cm 16cm 0.5cm 2cm,clip]{bibliography/PDF/Intel-8086-Family-users-manual.pdf}
  \end{center}
  
  \leftline{\scriptsize Intel 8086 Family User's guide, p.~162}
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Antrojo registro ir režimo kodavimas}

  \begin{center}
    \includegraphics[page=162,width=11cm,trim=1.3cm 0.8cm 1.5cm 16.1cm,clip]{bibliography/PDF/Intel-8086-Family-users-manual.pdf}
  \end{center}
  
  \leftline{\scriptsize Intel 8086 Family User's guide, p.~162}
\end{frame}

%------------------------------------------------------------------------------

\lstset{
  keywordstyle=\color{KwdColor},
  commentstyle=\color{CommentColor}\ttfamily,
  identifierstyle=\color{IdentifierColor},
  stringstyle=\color{StringColor},
  basicstyle=\ttfamily\tiny
}

\begin{frame}
\frametitle{MOV komanda}

  \texttt{nasm}:
  \begin{center}
    \begin{minipage}{0.85\textwidth}
      \lstinputlisting[language=C,linerange={5-18,20-22},frame=trBL]{examples/assembler/x86-nasm/mov.lst}
    \end{minipage}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{LEA komanda}

  \texttt{nasm}:
  \begin{center}
    \begin{minipage}{0.85\textwidth}
      \lstinputlisting[language=C,linerange={5-15,20-22},frame=trBL]{examples/assembler/x86-nasm/lea.lst}
    \end{minipage}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{XCHG komanda}

  \begin{center}
    \begin{minipage}{0.7\textwidth}
      \lstinputlisting[language=C,linerange={5-11,15-16},frame=trBL]{examples/assembler/x86-nasm/xchg.lst}
    \end{minipage}
  \end{center}
  
  \begin{quote}
    \small
    If a memory operand is referenced, the processor's locking
    protocol is automatically implemented for the duration of the
    exchange operation, regardless of the presence or absence of the
    LOCK prefix or of the value of the IOPL. (See the LOCK prefix
    description in this chapter for more information on the locking
    protocol.) This instruction is useful for implementing semaphores
    or similar data structures for process synchronization.
  \end{quote}
  \rightline{\scriptsize\mywebref{https://c9x.me/x86/html/file\_module\_x86\_id\_328.html}}
  \rightline{\scriptsize 2020-03-23}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{ADD, ADC komandos}

  \texttt{nasm}:
  \begin{center}
    \begin{minipage}{0.7\textwidth}
      \lstinputlisting[language=C,linerange={5-15,20-22},frame=trBL]{examples/assembler/x86-nasm/add-adc.lst}
    \end{minipage}
  \end{center}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{INC, DEC komandos}

  \begin{center}
    \begin{minipage}{0.9\textwidth}
      \lstinputlisting[language=C,linerange={5-10},frame=trBL]{examples/assembler/x86-nasm/inc-dec.lst}
    \end{minipage}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{REP STOS komandos}

  \begin{center}
    \begin{minipage}{0.9\textwidth}
      \lstinputlisting[language=C,linerange={5-11,16-18},frame=trBL]{examples/assembler/x86-nasm/rep-stos.lst}
    \end{minipage}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{LOOP komanda}

  \begin{center}
    \begin{minipage}{0.9\textwidth}
      \lstinputlisting[language=C,linerange={5-12},frame=trBL]{examples/assembler/x86-nasm/loop-imul.lst}
    \end{minipage}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{JMP,Jcc komandos}

  \begin{center}
    \begin{minipage}{0.9\textwidth}
      \lstinputlisting[language=C,linerange={5-13},frame=trBL]{examples/assembler/x86-nasm/jmp-jcc.lst}
    \end{minipage}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{PUSH/POP komandos}

  \begin{center}
    \begin{minipage}{0.9\textwidth}
      \lstinputlisting[language=C,linerange={5-13},frame=trBL]{examples/assembler/x86-nasm/push-pop.lst}
    \end{minipage}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{CALL, RET komandos}

  \begin{center}
    \begin{minipage}{0.9\textwidth}
      \lstinputlisting[language=C,linerange={5-6,11-12},frame=trBL]{examples/assembler/x86-nasm/call-ret.lst}
    \end{minipage}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Steko kadrai}

  \begin{center}
    \includegraphics[width=11cm]{drawings/calling-conventions/C-calling-convention.eps}
  \end{center}
  
\end{frame}

%% %------------------------------------------------------------------------------
%% 
%% \begin{frame}
%%   %%LANGUAGE en \frametitle{Calling conventions (16 bit)}
%%   %%LANGUAGE lt \frametitle{Kvietimo susitarimai}
%%   %%LANGUAGE ru \frametitle{Соглашения вызова}
%% 
%% \end{frame}
%% 
%% %------------------------------------------------------------------------------
%% 
%% \begin{frame}
%%   %%LANGUAGE en \frametitle{Calling conventions (64 bit)}
%%   %%LANGUAGE lt \frametitle{Kvietimo susitarimai (64 bitai)}
%%   %%LANGUAGE ru \frametitle{Соглашения вызова (64 разряда}
%% 
%% \end{frame}
%% 
%% %------------------------------------------------------------------------------

\begin{frame}
\frametitle{SYSCALL/INT, SYSRET/IRET}

  \begin{center}
    \begin{minipage}{0.9\textwidth}
      16-bit (\texttt{nasm}): 
      \lstinputlisting[language=C,linerange={7-9},frame=trBL]{examples/assembler/x86-nasm/call-ret.lst}

      64-bit (\texttt{yasm}): 
      \lstinputlisting[language=C,linerange={8-11,26-28},frame=trBL]{examples/assembler/x86_64-yasm/try.lst}
    \end{minipage}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}%%[allowframebreaks]
\frametitle{Šaltiniai}

  \renewcommand{\bibfont}{\scriptsize}
  \printbibliography

\end{frame}

%------------------------------------------------------------------------------                                                                                                          
\end{document}
% 2023-11-27 11:07:17 EET
