%--*- 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/Gutierrez-Osuna.bib}
\addbibresource{bibliography/Intel.bib}
\newcommand{\mycite}{\parencite}


\usepackage{colordvi}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{snakes}
\usepackage{verbatim}
\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{Mašinos kodas. Asembleris}
%%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{Paprastas Harvardo architektūros procesorius}

  \begin{center}
    \includegraphics[width=12cm]{drawings/Harvard-CPU-Logisim/overal.png}
  \end{center}
  
\end{frame}

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

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

  \begin{center}
    \includegraphics[width=12cm]{drawings/Harvard-CPU-Logisim/data-tract.png}
  \end{center}
  
\end{frame}

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

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

\begin{frame}[fragile]
\frametitle{Paprastas algoritmas}

\framesubtitle{Fibonačiо skaičiai}

  \begin{center}
    \begin{minipage}{0.4\textwidth}
      \lstinputlisting[language=C,firstline=3,frame=trBL]{examples/Fibonacci-numbers/fibonacci.c}
    \end{minipage}
    \hspace{1cm}
\hspace{0.5cm}
    \begin{minipage}{0.4\textwidth}
      \scriptsize
    
      \begin{enumerate}
\item[\textit{Žingsnis 0}.] Nustatyti
        $a \leftarrow 1$, $b \leftarrow 1$.

($a$ ir $b$ yra du paskutiniai sekos skaičiai)

\item[\textit{Žingsnis i}.] visiems
        $1 \le i \le N$:

        \begin{enumerate}[i]
          \scriptsize
\item laikinai išsaugoti $b$:
          $t \leftarrow b\,;$

\item nustatyti
          $b \leftarrow a + b\,;$

\item išvesti
          $b\,;$

\item nustatyti
          $a \leftarrow t\,;$
        \end{enumerate}

\item [\textit{Žingsnis $N+1$}.] Pabaiga
      \end{enumerate}
    \end{minipage}
  \end{center}
  
\end{frame}

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

\begin{frame}
\frametitle{Mašinos kodas}

  \begin{center}
    \begin{minipage}{0.4\textwidth}
      \lstinputlisting[language=C,firstline=3,frame=trBL]{examples/Fibonacci-numbers/fibonacci.c}
    \end{minipage}
    \hspace{1cm}
    \begin{minipage}{0.4\textwidth}
      \lstinputlisting[language=C,frame=trBL]{examples/Fibonacci-numbers/fib.hex}
    \end{minipage}
  \end{center}
  
\end{frame}

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

\begin{frame}
\frametitle{Asemblerio pavyzdys}

  \begin{center}
    \begin{minipage}{0.4\textwidth}
      \lstinputlisting[language=C,firstline=3,frame=trBL]{examples/Fibonacci-numbers/fibonacci.c}
    \end{minipage}
    \hspace{1cm}
    \begin{minipage}{0.4\textwidth}
      \lstset{language=[Motorola68k]Assembler}
      \lstinputlisting[frame=trBL]{examples/Fibonacci-numbers/fib.asm}
    \end{minipage}
  \end{center}
  
\end{frame}

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

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

  \begin{center}
    \begin{tabular}{ll|ll|l}
      \bf
Adresas
      &
      \bf
Mašinos kodas
      &
      \multicolumn{2}{l|}{\bf
Mnemonika
      } &
      \bf
Reikšmė
      \\
      \hline

      0000 &
      \color{KwdColor}02\color{IdentifierColor}0001 &
      \color{KwdColor}LDC & \color{IdentifierColor}1 &
      \tiny
Įkelti konstantą 1 į akumuliatorių
      \\

      0001 &
      \color{KwdColor}04\color{IdentifierColor}0000 &
      \color{KwdColor}ST & \color{IdentifierColor}0 &
      \tiny
Išsaugoti akumuliatorių adresu 0
      \\

      0002 &
      \color{KwdColor}04\color{IdentifierColor}0001 &
      \color{KwdColor}ST & \color{IdentifierColor}1\\

      0003 &
      \color{KwdColor}02\color{IdentifierColor}0000 &
      \color{KwdColor}LDC & \color{IdentifierColor}0\\

      0004 &
      \color{KwdColor}04\color{IdentifierColor}0002 &
      \color{KwdColor}ST & \color{IdentifierColor}2\\

      0005 &
      \color{KwdColor}03\color{IdentifierColor}0001 &
      \color{KwdColor}LD & \color{IdentifierColor}1 &
      \tiny
      %%BEGIN LANGUAGE lt
      Įkelti [0001]\footnote{\tiny[0001] -- duomenų atminties celės, kurios
      adresas yra 0001, turinys.} į akumuliatorių
      %%END LANGUAGE lt
      \\

      0006 &
      \color{KwdColor}0B\color{IdentifierColor}0000 &
      \color{KwdColor}ADD & \color{IdentifierColor}0 &
      \tiny
Pridėti prie akumuliatoriaus [0000]
      \\

      ... \\

      
      000D &
      \color{KwdColor}1A\color{IdentifierColor}0015 &
      \color{KwdColor}SUBC & \color{IdentifierColor}15H &
      \tiny
Atimti 21 iš akumuliatoriaus
      \\

      000E &
      \color{KwdColor}0A\color{IdentifierColor}0005 &
      \color{KwdColor}JNEG & \color{IdentifierColor}0005 &
      \tiny
Pereiti į prog.\ adresą 5, jei akum. < 0
      \\

      000F &
      \color{KwdColor}FF\color{IdentifierColor}FFFF &
      \color{KwdColor}HALT & &
      \tiny
Sustabdyti procesorių
      \\

    \end{tabular}
  \end{center}
  
\end{frame}

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

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

  \begin{center}
    \begin{tabular}{lll}
      \textcolor{KwdColor}{N} & \color{KwdColor}EQU & 21 \\      
      \textcolor{KwdColor}{A} & \color{KwdColor}\only<1>{EQU}\only<2>{DS} & \only<1>{0}\only<2>{1} \\
      \textcolor{KwdColor}{B} & \color{KwdColor}\only<1>{EQU}\only<2>{DS} & 1 \\
      \textcolor{KwdColor}{I} & \color{KwdColor}\only<1>{EQU}\only<2>{DS} & \only<1>{2}\only<2>{1} \\
    \end{tabular}

    \vspace{0.5\baselineskip}
    \begin{tabular}{ll|ll|l}
      \bf
Adresas
      &
      \bf
Mašinos kodas
      &
      \multicolumn{2}{l|}{\bf
Mnemonika
      } &
      \bf
Reikšmė
      \\
      \hline

      0000 &
      \color{KwdColor}02\color{IdentifierColor}0001 &
      \color{KwdColor}LDC & \color{IdentifierColor}1 &
      \tiny
Įkelti konstantą 1 į akumuliatorių
      \\

      0001 &
      \color{KwdColor}04\color{IdentifierColor}0000 &
      \color{KwdColor}ST & \color{IdentifierColor}A &
      \tiny
Išsaugoti akumuliatorių adresu A
      \\

      0002 &
      \color{KwdColor}04\color{IdentifierColor}0001 &
      \color{KwdColor}ST & \color{IdentifierColor}B\\

      0003 &
      \color{KwdColor}02\color{IdentifierColor}0000 &
      \color{KwdColor}LDC & \color{IdentifierColor}0\\

      0004 &
      \color{KwdColor}04\color{IdentifierColor}0002 &
      \color{KwdColor}ST & \color{IdentifierColor}I\\

      0005 &
      \color{KwdColor}03\color{IdentifierColor}0001 &
      \color{KwdColor}LD & \color{IdentifierColor}B &
      \tiny
      %%BEGIN LANGUAGE lt
      Įkelti [B]\footnote{\tiny[B] -- duomenų atminties celės, kuri
        talpina kintamąjį B, turinys.} į akumuliatorių
      %%END LANGUAGE lt
      %% Load acc. from mem. location B
      \\

      0006 &
      \color{KwdColor}0B\color{IdentifierColor}0000 &
      \color{KwdColor}ADD & \color{IdentifierColor}A &
      \tiny
Pridėti prie akumuliatoriaus [A]
      %% Add contents of location A to acc.
      \\

      ... \\

      
      000D &
      \color{KwdColor}1A\color{IdentifierColor}0015 &
      \color{KwdColor}SUBC & \color{IdentifierColor}N &
      \tiny
Atimti N (= 21) iš akumuliatoriaus
      %% Subtract 21 from accumulator
      \\

      000E &
      \color{KwdColor}0A\color{IdentifierColor}0005 &
      \color{KwdColor}JNEG & \color{IdentifierColor}0005 &
      \tiny
Pereiti į 0005, jei akumuliatorius < 0
      \\

    \end{tabular}
  \end{center}
  
\end{frame}

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

\begin{frame}
\frametitle{Žymės}

  \begin{center}
    \scriptsize
    \begin{tabular}{rlll}
                              &   & \color{KwdColor}ORG & 100 \\      
      \textcolor{KwdColor}{N} & : & \color{KwdColor}EQU & 21 \\      
      \textcolor{KwdColor}{A} & : & \color{KwdColor}DS  & 1 \\
      \textcolor{KwdColor}{B} & : & \color{KwdColor}DS  & 1 \\
      \textcolor{KwdColor}{I} & : & \color{KwdColor}DS  & 1 \\
    \end{tabular}

    \small
    \vspace{0.5\baselineskip}
    \begin{tabular}{ll|ll|l}
      \bf
Adresas
      &
      \bf
Mašinos kodas
      &
      \multicolumn{2}{l|}{\bf
Mnemonika
      } &
      \bf
Reikšmė
      \\
      \hline

      &
      \color{KwdColor}02\color{IdentifierColor}0001 &
      \color{KwdColor}LDC & \color{IdentifierColor}1 &
      \tiny
Įkelti konstantą 1 į akumuliatorių
      \\

      &
      \color{KwdColor}04\color{IdentifierColor}0000 &
      \color{KwdColor}ST & \color{IdentifierColor}A &
      \tiny
Išsaugoti akumuliatorių adresu A
      \\

      &
      \color{KwdColor}04\color{IdentifierColor}0001 &
      \color{KwdColor}ST & \color{IdentifierColor}B\\

      &
      \color{KwdColor}02\color{IdentifierColor}0000 &
      \color{KwdColor}LDC & \color{IdentifierColor}0\\

      &
      \color{KwdColor}04\color{IdentifierColor}0002 &
      \color{KwdColor}ST & \color{IdentifierColor}I\\

      \textcolor{IdentifierColor}{LOOP}: &
      \color{KwdColor}03\color{IdentifierColor}0001 &
      \color{KwdColor}LD & \color{IdentifierColor}B &
      \tiny
Įkelti atminties celę B į akumuliatorių
      \\

      &
      \color{KwdColor}0B\color{IdentifierColor}0000 &
      \color{KwdColor}ADD & \color{IdentifierColor}A &
      \tiny
Pridėti prie akumuliatoriaus A turinį
      \\

      ... \\

      
      &
      \color{KwdColor}1A\color{IdentifierColor}0015 &
      \color{KwdColor}SUBC & \color{IdentifierColor}N &
      \tiny
Atimti N (= 21) iš akumuliatoriaus
      \\

      &
      \color{KwdColor}0A\color{IdentifierColor}0005 &
      \color{KwdColor}JNEG & \color{IdentifierColor}LOOP &
      \tiny
Pereiti į LOOP, jei akumuliatorius < 0
      \\

    \end{tabular}
  \end{center}
  
\end{frame}

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

\begin{frame}
\frametitle{Asemblerio programa}

  \begin{center}
    \small
    \begin{tabular}{l|ll|l}
      \bf
Žymė
      &
      \bf
Operacija
      &
      \bf
Operandai
      &
      \bf
Komentarai
      \\
      \hline

                               & \color{KwdColor}ORG & 100 \\
      \textcolor{KwdColor}{N}: & \color{KwdColor}EQU & 21 &
      \tiny
; Kiek sekos narių reikia suskaičiuoti
      \\
      \textcolor{KwdColor}{A}: & \color{KwdColor}DS  & 1 \\
      \textcolor{KwdColor}{B}: & \color{KwdColor}DS  & 1 \\
      \textcolor{KwdColor}{I}: & \color{KwdColor}DS  & 1 \\

      &&&\\
      &
      \color{KwdColor}LDC & \color{IdentifierColor}1 &
      \tiny
; Įkelti 1 į akumuliatorių
      \\

      &
      \color{KwdColor}ST & \color{IdentifierColor}A &
      \tiny
; Išsaugoti akumuliatorių celėje A
      \\

      &
      \color{KwdColor}ST & \color{IdentifierColor}B\\

      &
      \color{KwdColor}LDC & \color{IdentifierColor}0\\

      &
      \color{KwdColor}ST & \color{IdentifierColor}I\\

      \textcolor{IdentifierColor}{LOOP}: &
      \color{KwdColor}LD & \color{IdentifierColor}B &
      \tiny
; Įkelti B turinį į akumuliatorių
      \\

      &
      \color{KwdColor}ADD & \color{IdentifierColor}A &
      \tiny
; Pridėti A turinį prie akumuliatoriaus
      \\

      ... &&& \\

      
      &
      \color{KwdColor}SUBC & \color{IdentifierColor}N &
      \tiny
; Atimti 21 iš akumuliatoriaus
      \\

      &
      \color{KwdColor}JNEG & \color{IdentifierColor}LOOP &
      \tiny
; Pakartoti ciklą, jei akumuliatorius < 0
      \\

    \end{tabular}
  \end{center}
  
\end{frame}

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

\begin{frame}
\frametitle{Adresavimo režimai}

  \begin{center}
    \begin{tabular}{l|l|p{0.4\textwidth}}
      \textbf{
Režimas
      } & \textbf{
Veiksmai
      } & \textbf{
Aprašymas
      } \\
      \hline

Betarpiškas
      & A $\leftarrow$ operand &
      {
        \raggedright\footnotesize
Naudojama reikšmė, nurodyta komandoje
      }
      \\

Tiesioginis
      & A $\leftarrow$ [operand] &
      {
        \raggedright\footnotesize
Reikšmės \textit{adresas} nurodytas komandoje
      }
      \\

Registrinis
      & A $\leftarrow$ IDX &
      {
        \raggedright\footnotesize
Naudojama reikšmė yra registre
      }
      \\

Netiesioginis
      & A $\leftarrow$ [IDX] &
      {
        \raggedright\footnotesize
Reikšmės \textit{adresas} yra registre
      }
      \\

Indeksinis
      & \footnotesize A $\leftarrow$ operand[IDX] &
      {
        \raggedright\footnotesize
Reikšmės adresas yra indekso registro reikšmė + operandas
      }
      \\

    \end{tabular}
  \end{center}
  
\end{frame}

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

\begin{frame}
\frametitle{Programuotojui matomas procesoriaus modelis}


  %%BEGIN LANGUAGE lt
  Programuotojo požiūriu, apie kompiuterį ar procesorių reikia nurodyti:
  %%END LANGUAGE lt


  \begin{itemize}
  \item

    %%BEGIN LANGUAGE lt
    \textbf{Procesoriaus registrus}, matomus programuotojui
    %%END LANGUAGE lt


  \item    

    %%BEGIN LANGUAGE lt
    Procesoriaus \textbf{komandų sistemą (ISA)}
    %%END LANGUAGE lt


  \item

    %%BEGIN LANGUAGE lt
    Procesoriaus \textbf{adresavimo režimus}
    %%END LANGUAGE lt


  \item

    %%BEGIN LANGUAGE lt
    Procesoriaus \textbf{atminties organizaciją}
    %%END LANGUAGE lt

    
  \item

    %%BEGIN LANGUAGE lt
    Procesoriaus \textbf{įvestį ir išvestį}
    %%END LANGUAGE lt

    
  \end{itemize}

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

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

\begin{frame}
\frametitle{Harvardo architektūros 16 bitų procesorius}

  \begin{itemize}
  \item
Registrai:
    \texttt{A, PC, IDX}

  \item 
Komandų formatas:
    \fbox{OPC (8
bitai
      )}\fbox{ADDR/IMM (16
bitų
      )}

  \item
Žodžio plotis:

    \begin{itemize}
    \item
duomenų žodžio –
      16
bitų

    \item
komandų žodžio –
      24 ($\text{8}+\text{16}$)
bitai

    \end{itemize}
    
  \item
Adreso plotis:
    16
bitų
    
  \item
Adresuojamas: žodis
    
  \item
Adresų erdvė: vientisa
    
  \item
Komandų sistema:
akumuliatorinė architektūra;
    \texttt{LD, LDC, ST, ADD, JNZ, JNEG, ...}
    
  \item
    %%BEGIN LANGUAGE lt
    Įvestis/išvestis: prievadai atskiroje adresų erdvėje; pertraukimų
    nėra; vienas įvesties ir vienas išvesties prievadas
    %%END LANGUAGE lt
    
  \end{itemize}
  
\end{frame}

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

\begin{frame}
\frametitle{Registrai}

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

  \rightline{\scriptsize\mycite{INTEL1979}}

\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}
  \begin{center}
    \includegraphics[width=3cm]{drawings/Intel/8086-segments.eps}
  \end{center}
  
\end{frame}

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

\begin{frame}
\frametitle{Apibendrinimas}

  \begin{itemize}
  \item
    %%BEGIN LANGUAGE lt
    Mašinos kalba yra dvejetainiai skaičiai, paprastai užrašomi
    šešioliktainėje sistemoje
    %%END LANGUAGE lt
  \item
    %%BEGIN LANGUAGE lt
    Komandų mnemonikos žymiai palengvina operacijų aprašymą ir įsiminimą
    %%END LANGUAGE lt
  \item
    %%BEGIN LANGUAGE lt
    Kad palengvinti programavimą mašinos kalba, naudojami asembleriai
    %%END LANGUAGE lt
  \item
    %%BEGIN LANGUAGE lt
    Pagrindinės asemblerio sąvokos: žymės, operacijos, operandai,
    pseudoinstrukcijos, komentarai
    %%END LANGUAGE lt
  \item
    %%BEGIN LANGUAGE lt
    Kompiuterio ar procesoriaus architektūrą galime aprašyti,
    nurodydami keletą charakteristikų, matomų programuotojui
    %%END LANGUAGE lt
  \end{itemize}
  
\end{frame}

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

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

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

\end{frame}

%------------------------------------------------------------------------------                                                                                                          
\end{document}
% 2021-10-18 09:52:37 EEST
