<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Memory on Jefferson Oliveira</title><link>https://jeffersonmourak.com/tags/memory/</link><description>Recent content in Memory on Jefferson Oliveira</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>All content provided by this website are my own opinons and beliefs and are distrubuted under the &lt;br/></copyright><lastBuildDate>Sun, 19 Jan 2025 08:27:04 -0300</lastBuildDate><atom:link href="https://jeffersonmourak.com/tags/memory/index.xml" rel="self" type="application/rss+xml"/><item><title>Lembra de mim?</title><link>https://jeffersonmourak.com/blog/memory/</link><pubDate>Sun, 19 Jan 2025 08:27:04 -0300</pubDate><guid>https://jeffersonmourak.com/blog/memory/</guid><category domain="https://jeffersonmourak.com/tags/cpu/">CPU</category><category domain="https://jeffersonmourak.com/tags/memory/">Memory</category><category domain="https://jeffersonmourak.com/tags/combinational/">Combinational</category><category domain="https://jeffersonmourak.com/tags/sequential/">Sequential</category><description>&lt;blockquote>
&lt;p>Olá todo mundo, este é o terceiro artigo na série sobre computadores, e também o último com esse cabeçalho aqui, pois daqui para a frente é recomendado que você já tenha lido os dois artigos anteriores:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://jeffersonmourak.com/blog/logic-gates/">Portas lógicas&lt;/a>.&lt;/li>
&lt;li>&lt;a href="https://jeffersonmourak.com/blog/the-binary/">Prazer, Binário.&lt;/a>.&lt;/li>
&lt;/ul>&lt;/blockquote>
&lt;p>Nos artigos anteriores, nós vimos como portas lógicas podem ser usadas para fazer comparações e também calcular operações aritméticas, porém ainda não vimos como o computador pode guardar uma informação ao longo do tempo.&lt;/p></description><content:encoded><![CDATA[<blockquote>
<p>Olá todo mundo, este é o terceiro artigo na série sobre computadores, e também o último com esse cabeçalho aqui, pois daqui para a frente é recomendado que você já tenha lido os dois artigos anteriores:</p>
<ul>
<li><a href="https://jeffersonmourak.com/blog/logic-gates/">Portas lógicas</a>.</li>
<li><a href="https://jeffersonmourak.com/blog/the-binary/">Prazer, Binário.</a>.</li>
</ul></blockquote>
<p>Nos artigos anteriores, nós vimos como portas lógicas podem ser usadas para fazer comparações e também calcular operações aritméticas, porém ainda não vimos como o computador pode guardar uma informação ao longo do tempo.</p>
<p>Outra coisa que também iremos fazer aqui é categorizar cada tipo de chip: os que foram mostrados anteriormente são <em><strong>combinacionais</strong></em>, o que significa que eles não precisam de nada além de sinais nas suas entradas para poder computar um resultado, mas existem também os <em><strong>sequenciais</strong></em>. A diferença entre eles é que o sequencial depende não só dos sinais das entradas, mas também do valor anteriormente processado.</p>
<p>Um jeito muito prático de usar portas lógicas para guardar informações é usando um chip chamado de <em><strong>flip-flop</strong></em>, que está representado abaixo. Ele contém 2 entradas: a de cima <code>set</code> e a de baixo <code>reset</code> (você pode clicar no circuito abaixo para interagir com eles).</p>
<p><em>Interactive circ widget &mdash; <a href="https://jeffersonmourak.com/blog/memory/">view it on the blog</a>.</em></p>
<pre><code>╭───────╮     ╭───╮           ╭───╮     ╭───╮
│ reset ├○───▶┤NOT├○╮     ╭──▶┤   │ ╭──▶┤LED│
╰───────╯     ╰───╯ │     │   │AND├○●   ╰───╯
                    ╰─────┼──▶┤   │ │        
                          │   ╰───╯ │        
            ╭─────────────┼─────────╯        
╭─────╮     │ ╭─────────╮ │                  
│ set ├○╮   ╰▶┤         │ │                  
╰─────╯ │     │[or:_or_]├○╯                  
        ╰────▶┤         │                    
              ╰─────────╯                    </code></pre>
<p>Se parar para analisar, é bem simples: seguindo a trilha do <code>set</code>, verá que há duas portas lógicas no caminho, uma <code>OR</code> e uma <code>AND</code>. Uma das entradas da porta <code>OR</code> está ligada com o resultado da <code>AND</code> lá no fim do chip. Essa combinação faz com que, quando temos <strong>0</strong> e é nos dado um valor <strong>1</strong>, a porta <code>OR</code> vai resultar em <strong>1</strong>, e a <code>AND</code> também.</p>
<p>Porém, quando removemos o sinal do <code>set</code>, o valor que foi anteriormente colocado é persistido porque agora o <code>OR</code> está mantendo o estado que mantém o <code>AND</code> também no estado anterior. Problema resolvido, certo? Não! Perceba que nosso circuito agora está travado, pois não há como sair desse estado a não ser que o <code>AND</code> passe a ter um outro valor, e é para isso que serve a porta <code>reset</code>: ela está ligada a um <code>NOT</code>, ou seja, enquanto ela estiver desligada (0), o seu resultado vai ser 1 (ligado), e vice-versa.</p>
<p>Uma evolução que podemos fazer no <em><strong>flip-flop</strong></em> é transformá-lo em um <em><strong>Registrador</strong></em>. No registrador, podemos escolher se é ou não a hora de ler o nosso sinal e guardá-lo, e subsequentemente reescrevê-lo, e tudo isso ao nosso bel-prazer. Existem muitas formas de atingir esse chip, então vou usar a implementação demonstrada pelo <a href="https://www.youtube.com/watch?v=I0-izyq6q5s">Sebastian Lague</a>.</p>
<p>Nela, a gente só precisa adicionar mais 3 portas lógicas e pronto!</p>
<p><em>Interactive circ widget &mdash; <a href="https://jeffersonmourak.com/blog/memory/">view it on the blog</a>.</em></p>
<pre><code>╭──────╮        ╭───╮     ╭───╮     ╭───╮     ╭───╮     ╭───╮     ╭───╮     ╭───╮     ╭───╮
│ data ├○──●───▶┤   │  ╭─▶┤NOT├○┬──▶┤NOT├○───▶┤   │ ╭──▶┤NOT├○╮ ╭▶┤   │ ╭──▶┤NOT├○●──▶┤LED│
╰──────╯   │    │AND├○─╯  ╰───╯ │   ╰───╯     │AND├○╯   ╰───╯ │ │ │AND├○╯   ╰───╯ │   ╰───╯
           │╭──▶┤   │           │           ╭▶┤   │           ╰─┼▶┤   │           │        
           ││   ╰───╯           │           │ ╰───╯             │ ╰───╯           │        
           ││                   ├───────────┼───────────────────╯                 │        
╭─────────╮││   ╭───╮     ╭───╮ │           │                                     │        
│ enabled ├○┼──▶┤NOT├○───▶┤   │ │           ╰─────────────────────────────────────╯        
╰─────────╯ │   ╰───╯     │AND├○╯                                                          
            ╰────────────▶┤   │                                                            
                          ╰───╯                                                            </code></pre>
<p>Se a gente destrinchar um pouco, o que acontece é o seguinte: a entrada superior, que agora chamaremos de <code>data</code>, só será salva no <em><strong>flip-flop</strong></em> quando a entrada inferior, que também mudou o nome, agora se chama <code>enabled</code>. Ou seja, em vez de usar duas entradas, uma para salvar e outra para apagar, essa combinação de <code>AND</code>s e <code>NOT</code> escolhe qual operação será feita.</p>
<ul>
<li>Se <code>data</code> = 1 e <code>enabled</code> = 1, então é a mesma coisa que ligar a entrada <code>set</code> do <em><strong>flip-flop</strong></em>.</li>
<li>Se <code>data</code> = 0 e <code>enabled</code> = 1, então é a mesma coisa que ligar a entrada <code>reset</code> do <em><strong>flip-flop</strong></em>.
Perceba que o <code>enabled</code> precisa sempre estar ativado para que possa salvar o sinal que foi colocado em <code>data</code>.</li>
</ul>
<p>Uma outra coisa que podemos fazer é pegar inspiração no artigo anterior, que no final a gente aprende que, se juntarmos vários Adders, nós podemos fazer contas com múltiplos dígitos. Na memória é do mesmo jeito: juntando vários registradores, você pode fornecer uma entrada para cada <code>data</code> e compartilhar o sinal do <code>enabled</code>, e assim você pode salvar os valores de um número binário inteiro.</p>
<p>Por enquanto, a gente se despede por aqui, até a próxima 😄</p>
<figure>
  <img src="https://media2.giphy.com/media/v1.Y2lkPTc5MGI3NjExOXlucmJmbW5mZWp4MGRpOXhpZWZwczdma2xmemIxZGVjZ3hiZG5sciZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/m9eG1qVjvN56H0MXt8/giphy.gif" alt="Xauzinho!" loading="lazy">
  <figcaption>Xauzinho!</figcaption>
</figure><h2 id="referências">Referências</h2>
<ul>
<li><a href="https://www.youtube.com/watch?v=I0-izyq6q5s">How Do Computers Remember? (YouTube)</a></li>
<li><a href="https://www.youtube.com/watch?v=KM0DdEaY5sY">SR latch (YouTube)</a></li>
<li><a href="https://www.youtube.com/watch?v=peCh_859q7Q">D latch</a></li>
<li><a href="https://www.youtube.com/watch?v=HjneAhCy2N4">HOW TRANSISTORS RUN CODE? (YouTube)</a></li>
<li><a href="https://www.nand2tetris.org/">From Nand to Tetris</a></li>
</ul>
]]></content:encoded></item><item><title>Remember me?</title><link>https://jeffersonmourak.com/blog/memory-en/</link><pubDate>Sun, 19 Jan 2025 08:27:04 -0200</pubDate><guid>https://jeffersonmourak.com/blog/memory-en/</guid><category domain="https://jeffersonmourak.com/tags/cpu/">CPU</category><category domain="https://jeffersonmourak.com/tags/memory/">Memory</category><category domain="https://jeffersonmourak.com/tags/combinational/">Combinational</category><category domain="https://jeffersonmourak.com/tags/sequential/">Sequential</category><description>&lt;blockquote>
&lt;p>Hey Y&amp;rsquo;all! This is a translation of my blog post originally written in Portuguese.&lt;/p>&lt;/blockquote>
&lt;blockquote>
&lt;p>Hello everyone, this is the third article in the series about computers, and also the last one with this header here, because from here on it&amp;rsquo;s recommended that you have already read the two previous articles:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://jeffersonmourak.com/blog/logic-gates/">Logic gates&lt;/a>.&lt;/li>
&lt;li>&lt;a href="https://jeffersonmourak.com/blog/the-binary/">Pleasure to meet you, Binary.&lt;/a>.&lt;/li>
&lt;/ul>&lt;/blockquote>
&lt;p>In the previous articles, we saw how logic gates can be used to make comparisons and also calculate arithmetic operations, but we haven&amp;rsquo;t yet seen how the computer can store information over time.&lt;/p></description><content:encoded><![CDATA[<blockquote>
<p>Hey Y&rsquo;all! This is a translation of my blog post originally written in Portuguese.</p></blockquote>
<blockquote>
<p>Hello everyone, this is the third article in the series about computers, and also the last one with this header here, because from here on it&rsquo;s recommended that you have already read the two previous articles:</p>
<ul>
<li><a href="https://jeffersonmourak.com/blog/logic-gates/">Logic gates</a>.</li>
<li><a href="https://jeffersonmourak.com/blog/the-binary/">Pleasure to meet you, Binary.</a>.</li>
</ul></blockquote>
<p>In the previous articles, we saw how logic gates can be used to make comparisons and also calculate arithmetic operations, but we haven&rsquo;t yet seen how the computer can store information over time.</p>
<p>Another thing we&rsquo;ll do here is categorize each type of chip: the ones shown previously are <em><strong>combinational</strong></em>, which means they don&rsquo;t need anything beyond signals at their inputs to be able to compute a result, but there are also <em><strong>sequential</strong></em> ones. The difference between them is that sequential depends not only on the input signals, but also on the previously processed value.</p>
<p>A very practical way to use logic gates to store information is using a chip called <em><strong>flip-flop</strong></em>, which is represented below. It contains 2 inputs: the top one <code>set</code> and the bottom one <code>reset</code> (you can click on the circuit below to interact with them).</p>
<p><em>Interactive circ widget &mdash; <a href="https://jeffersonmourak.com/blog/memory-en/">view it on the blog</a>.</em></p>
<pre><code>╭───────╮     ╭───╮           ╭───╮     ╭───╮
│ reset ├○───▶┤NOT├○╮     ╭──▶┤   │ ╭──▶┤LED│
╰───────╯     ╰───╯ │     │   │AND├○●   ╰───╯
                    ╰─────┼──▶┤   │ │        
                          │   ╰───╯ │        
            ╭─────────────┼─────────╯        
╭─────╮     │ ╭─────────╮ │                  
│ set ├○╮   ╰▶┤         │ │                  
╰─────╯ │     │[or:_or_]├○╯                  
        ╰────▶┤         │                    
              ╰─────────╯                    </code></pre>
<p>If you stop to analyze, it&rsquo;s quite simple: following the <code>set</code> trail, you&rsquo;ll see there are two logic gates in the path, an <code>OR</code> and an <code>AND</code>. One of the <code>OR</code> gate inputs is connected to the result of the <code>AND</code> at the end of the chip. This combination makes it so that when we have <strong>0</strong> and are given a value <strong>1</strong>, the <code>OR</code> gate will result in <strong>1</strong>, and the <code>AND</code> will also.</p>
<p>However, when we remove the signal from <code>set</code>, the value that was previously placed is persisted because now the <code>OR</code> is maintaining the state that keeps the <code>AND</code> also in the previous state. Problem solved, right? No! Notice that our circuit is now locked, as there&rsquo;s no way to get out of this state unless the <code>AND</code> gets another value, and that&rsquo;s what the <code>reset</code> gate is for: it&rsquo;s connected to a <code>NOT</code>, meaning while it&rsquo;s off (0), its result will be 1 (on), and vice versa.</p>
<p>An evolution we can make to the <em><strong>flip-flop</strong></em> is to transform it into a <em><strong>Register</strong></em>. In the register, we can choose whether it&rsquo;s time or not to read our signal and store it, and subsequently rewrite it, all at our leisure. There are many ways to achieve this chip, so I&rsquo;ll use the implementation demonstrated by <a href="https://www.youtube.com/watch?v=I0-izyq6q5s">Sebastian Lague</a>.</p>
<p>In it, we just need to add 3 more logic gates and that&rsquo;s it!</p>
<p><em>Interactive circ widget &mdash; <a href="https://jeffersonmourak.com/blog/memory-en/">view it on the blog</a>.</em></p>
<pre><code>╭──────╮        ╭───╮     ╭───╮     ╭───╮     ╭───╮     ╭───╮     ╭───╮     ╭───╮     ╭───╮
│ data ├○──●───▶┤   │  ╭─▶┤NOT├○┬──▶┤NOT├○───▶┤   │ ╭──▶┤NOT├○╮ ╭▶┤   │ ╭──▶┤NOT├○●──▶┤LED│
╰──────╯   │    │AND├○─╯  ╰───╯ │   ╰───╯     │AND├○╯   ╰───╯ │ │ │AND├○╯   ╰───╯ │   ╰───╯
           │╭──▶┤   │           │           ╭▶┤   │           ╰─┼▶┤   │           │        
           ││   ╰───╯           │           │ ╰───╯             │ ╰───╯           │        
           ││                   ├───────────┼───────────────────╯                 │        
╭─────────╮││   ╭───╮     ╭───╮ │           │                                     │        
│ enabled ├○┼──▶┤NOT├○───▶┤   │ │           ╰─────────────────────────────────────╯        
╰─────────╯ │   ╰───╯     │AND├○╯                                                          
            ╰────────────▶┤   │                                                            
                          ╰───╯                                                            </code></pre>
<p>If we break it down a bit, what happens is the following: the upper input, which we&rsquo;ll now call <code>data</code>, will only be saved in the <em><strong>flip-flop</strong></em> when the lower input, which also changed names, now called <code>enabled</code>. So instead of using two inputs, one to save and another to erase, this combination of <code>AND</code>s and <code>NOT</code> chooses which operation will be performed.</p>
<ul>
<li>If <code>data</code> = 1 and <code>enabled</code> = 1, then it&rsquo;s the same as turning on the <code>set</code> input of the <em><strong>flip-flop</strong></em>.</li>
<li>If <code>data</code> = 0 and <code>enabled</code> = 1, then it&rsquo;s the same as turning on the <code>reset</code> input of the <em><strong>flip-flop</strong></em>.
Notice that <code>enabled</code> always needs to be activated so that it can save the signal that was placed in <code>data</code>.</li>
</ul>
<p>Another thing we can do is take inspiration from the previous article, where at the end we learned that if we combine several Adders, we can do calculations with multiple digits. In memory it&rsquo;s the same way: combining several registers, you can provide an input for each <code>data</code> and share the <code>enabled</code> signal, and thus you can save the values of an entire binary number.</p>
<p>For now, we say goodbye here, see you next time 😄</p>
<figure>
  <img src="https://media2.giphy.com/media/v1.Y2lkPTc5MGI3NjExOXlucmJmbW5mZWp4MGRpOXhpZWZwczdma2xmemIxZGVjZ3hiZG5sciZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/m9eG1qVjvN56H0MXt8/giphy.gif" alt="Bye bye!" loading="lazy">
  <figcaption>Bye bye!</figcaption>
</figure><h2 id="references">References</h2>
<ul>
<li><a href="https://www.youtube.com/watch?v=I0-izyq6q5s">How Do Computers Remember? (YouTube)</a></li>
<li><a href="https://www.youtube.com/watch?v=KM0DdEaY5sY">SR latch (YouTube)</a></li>
<li><a href="https://www.youtube.com/watch?v=peCh_859q7Q">D latch</a></li>
<li><a href="https://www.youtube.com/watch?v=HjneAhCy2N4">HOW TRANSISTORS RUN CODE? (YouTube)</a></li>
<li><a href="https://www.nand2tetris.org/">From Nand to Tetris</a></li>
</ul>
]]></content:encoded></item></channel></rss>