CAP/docs/html/_modules/Lib/FunctionData.html
2024-10-20 19:14:34 +02:00

292 lines
28 KiB
HTML

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lib.FunctionData &mdash; MiniC documentation</title>
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
<script src="../../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/sphinx_highlight.js"></script>
<script src="../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home">
MiniC
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../api/Lib.Errors.html">Base library - Errors</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Lib.Statement.html">Base library - Statement</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Lib.RiscV.html">Base library - RISC-V instructions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Lib.Operands.html">Base library - Operands</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Lib.FunctionData.html">Base library - Function data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Lib.Graphes.html">Base library - Graphs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Lib.LinearCode.html">Linear intermediate representation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Lib.Allocator.html">Temporary allocation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Lib.CFG.html">Control Flow Graph - CFG and Basic blocks</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Lib.Terminator.html">Control Flow Graph - Terminators</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Lib.Dominators.html">SSA form - Dominance frontier</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Lib.PhiNode.html">SSA form - Phi Nodes</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">MiniC</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="../index.html">Module code</a></li>
<li class="breadcrumb-item active">Lib.FunctionData</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for Lib.FunctionData</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This file defines the base class :py:class:`FunctionData`,</span>
<span class="sd">containing metadata on a RiscV function, as well as utility</span>
<span class="sd">functions common to the different intermediate representations.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="p">(</span><span class="n">List</span><span class="p">,</span> <span class="n">Callable</span><span class="p">,</span> <span class="n">TypeVar</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">Lib.Errors</span> <span class="kn">import</span> <span class="n">AllocationError</span>
<span class="kn">from</span> <span class="nn">Lib.Operands</span> <span class="kn">import</span> <span class="p">(</span>
<span class="n">Offset</span><span class="p">,</span> <span class="n">Temporary</span><span class="p">,</span> <span class="n">TemporaryPool</span><span class="p">,</span>
<span class="n">S</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">FP</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">Lib.Statement</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Statement</span><span class="p">,</span> <span class="n">Instruction</span><span class="p">,</span> <span class="n">Label</span><span class="p">,</span> <span class="n">Comment</span><span class="p">)</span>
<div class="viewcode-block" id="FunctionData"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData">[docs]</a><span class="k">class</span> <span class="nc">FunctionData</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Stores some metadata on a RiscV function:</span>
<span class="sd"> name of the function, label names, temporary variables</span>
<span class="sd"> (using :py:class:`Lib.Operands.TemporaryPool`),</span>
<span class="sd"> and div_by_zero label.</span>
<span class="sd"> This class is usually used indirectly through the</span>
<span class="sd"> different intermediate representations we work with,</span>
<span class="sd"> such as :py:attr:`Lib.LinearCode.LinearCode.fdata`.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">_nblabel</span><span class="p">:</span> <span class="nb">int</span>
<span class="n">_dec</span><span class="p">:</span> <span class="nb">int</span>
<span class="n">_pool</span><span class="p">:</span> <span class="n">TemporaryPool</span>
<span class="n">_name</span><span class="p">:</span> <span class="nb">str</span>
<span class="n">_label_div_by_zero</span><span class="p">:</span> <span class="n">Label</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_nblabel</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_dec</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_pool</span> <span class="o">=</span> <span class="n">TemporaryPool</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_name</span> <span class="o">=</span> <span class="n">name</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_label_div_by_zero</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fresh_label</span><span class="p">(</span><span class="s2">&quot;div_by_zero&quot;</span><span class="p">)</span>
<div class="viewcode-block" id="FunctionData.get_name"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData.get_name">[docs]</a> <span class="k">def</span> <span class="nf">get_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the name of the function.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_name</span></div>
<div class="viewcode-block" id="FunctionData.fresh_tmp"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData.fresh_tmp">[docs]</a> <span class="k">def</span> <span class="nf">fresh_tmp</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Temporary</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return a new fresh Temporary,</span>
<span class="sd"> which is added to the pool.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pool</span><span class="o">.</span><span class="n">fresh_tmp</span><span class="p">()</span></div>
<div class="viewcode-block" id="FunctionData.fresh_offset"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData.fresh_offset">[docs]</a> <span class="k">def</span> <span class="nf">fresh_offset</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Offset</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return a new offset in the memory stack.</span>
<span class="sd"> Offsets are decreasing relative to FP.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_dec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dec</span> <span class="o">+</span> <span class="mi">1</span>
<span class="c1"># For ld or sd, an offset on 12 signed bits is expected</span>
<span class="c1"># Raise an error if the offset is too big</span>
<span class="k">if</span> <span class="o">-</span><span class="mi">8</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dec</span> <span class="o">&lt;</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">**</span> <span class="mi">11</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">AllocationError</span><span class="p">(</span>
<span class="s2">&quot;Offset given by the allocation too big to be manipulated (</span><span class="si">{}</span><span class="s2">), sorry.&quot;</span>
<span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_dec</span><span class="p">))</span>
<span class="k">return</span> <span class="n">Offset</span><span class="p">(</span><span class="n">FP</span><span class="p">,</span> <span class="o">-</span><span class="mi">8</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dec</span><span class="p">)</span></div>
<div class="viewcode-block" id="FunctionData.get_offset"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData.get_offset">[docs]</a> <span class="k">def</span> <span class="nf">get_offset</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the current offset in the memory stack.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dec</span></div>
<span class="k">def</span> <span class="nf">_fresh_label_name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return a new unique label name based on the given string.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_nblabel</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nblabel</span> <span class="o">+</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">name</span> <span class="o">+</span> <span class="s2">&quot;_&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_nblabel</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;_&quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">_name</span>
<div class="viewcode-block" id="FunctionData.fresh_label"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData.fresh_label">[docs]</a> <span class="k">def</span> <span class="nf">fresh_label</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Label</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return a new label, with a unique name based on the given string.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">Label</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_fresh_label_name</span><span class="p">(</span><span class="n">name</span><span class="p">))</span></div>
<div class="viewcode-block" id="FunctionData.get_label_div_by_zero"><a class="viewcode-back" href="../../api/Lib.FunctionData.html#Lib.FunctionData.FunctionData.get_label_div_by_zero">[docs]</a> <span class="k">def</span> <span class="nf">get_label_div_by_zero</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Label</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_label_div_by_zero</span></div></div>
<span class="n">_T</span> <span class="o">=</span> <span class="n">TypeVar</span><span class="p">(</span><span class="s2">&quot;_T&quot;</span><span class="p">,</span> <span class="n">bound</span><span class="o">=</span><span class="n">Statement</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_iter_statements</span><span class="p">(</span>
<span class="n">listIns</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">_T</span><span class="p">],</span> <span class="n">f</span><span class="p">:</span> <span class="n">Callable</span><span class="p">[[</span><span class="n">_T</span><span class="p">],</span> <span class="n">List</span><span class="p">[</span><span class="n">_T</span><span class="p">]])</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">_T</span> <span class="o">|</span> <span class="n">Comment</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Iterate over instructions.</span>
<span class="sd"> For each real instruction i (not label or comment), replace it</span>
<span class="sd"> with the list of instructions given by f(i).</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">newListIns</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">_T</span> <span class="o">|</span> <span class="n">Comment</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">old_i</span> <span class="ow">in</span> <span class="n">listIns</span><span class="p">:</span>
<span class="c1"># Do nothing for label or comment</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">old_i</span><span class="p">,</span> <span class="n">Instruction</span><span class="p">):</span>
<span class="n">newListIns</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">old_i</span><span class="p">)</span>
<span class="k">continue</span>
<span class="n">new_i_list</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">old_i</span><span class="p">)</span>
<span class="c1"># Otherwise, replace the instruction by the list</span>
<span class="c1"># returned by f, with comments giving the replacement</span>
<span class="n">newListIns</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Comment</span><span class="p">(</span><span class="s2">&quot;Replaced &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">old_i</span><span class="p">)))</span>
<span class="n">newListIns</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">new_i_list</span><span class="p">)</span>
<span class="k">return</span> <span class="n">newListIns</span>
<span class="k">def</span> <span class="nf">_print_code</span><span class="p">(</span><span class="n">listIns</span><span class="p">:</span> <span class="n">List</span><span class="p">,</span> <span class="n">fdata</span><span class="p">:</span> <span class="n">FunctionData</span><span class="p">,</span> <span class="n">output</span><span class="p">,</span>
<span class="n">init_label</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fin_label</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fin_div0</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Please use print_code from LinearCode or CFG, not directly this one.</span>
<span class="sd"> Print the instructions from listIns, forming fdata, on output.</span>
<span class="sd"> If init_label is given, add an initial jump to it before the generated code.</span>
<span class="sd"> If fin_label is given, add it after the generated code.</span>
<span class="sd"> If fin_div0 is given equal to true, add the code for returning an</span>
<span class="sd"> error when dividing by 0, at the very end.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># compute size for the local stack - do not forget to align by 16</span>
<span class="n">fo</span> <span class="o">=</span> <span class="n">fdata</span><span class="o">.</span><span class="n">get_offset</span><span class="p">()</span> <span class="c1"># allocate enough memory for stack</span>
<span class="c1"># Room for S_i (except S_0 which is fp) and T_i backup</span>
<span class="n">fo</span> <span class="o">+=</span> <span class="nb">len</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">T</span><span class="p">)</span>
<span class="n">cardoffset</span> <span class="o">=</span> <span class="mi">8</span> <span class="o">*</span> <span class="p">(</span><span class="n">fo</span> <span class="o">+</span> <span class="p">(</span><span class="mi">0</span> <span class="k">if</span> <span class="n">fo</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">1</span><span class="p">))</span> <span class="o">+</span> <span class="mi">16</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
<span class="s2">&quot;##Automatically generated RISCV code, MIF08 &amp; CAP</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">comment</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;##</span><span class="si">{}</span><span class="s2"> version</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">comment</span><span class="p">))</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n\n</span><span class="s2">##prelude</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="c1"># We put an li t0, cardoffset in case it is greater than 2**11</span>
<span class="c1"># We use t0 because it is caller-saved</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="s2"> .text</span>
<span class="s2"> .globl </span><span class="si">{0}</span>
<span class="si">{0}</span><span class="s2">:</span>
<span class="s2"> li t0, </span><span class="si">{1}</span>
<span class="s2"> sub sp, sp, t0</span>
<span class="s2"> sd ra, 0(sp)</span>
<span class="s2"> sd fp, 8(sp)</span>
<span class="s2"> add fp, sp, t0</span>
<span class="s2">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">fdata</span><span class="o">.</span><span class="n">get_name</span><span class="p">(),</span> <span class="n">cardoffset</span><span class="p">))</span>
<span class="c1"># Stack in RiscV is managed with SP</span>
<span class="k">if</span> <span class="n">init_label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="c1"># Add a jump to init_label before the generated code.</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="s2"> j </span><span class="si">{0}</span>
<span class="s2">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">init_label</span><span class="p">))</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n\n</span><span class="s2">##Generated Code</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="c1"># Generated code</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">listIns</span><span class="p">:</span>
<span class="n">i</span><span class="o">.</span><span class="n">printIns</span><span class="p">(</span><span class="n">output</span><span class="p">)</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n\n</span><span class="s2">##postlude</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">fin_label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="c1"># Add fin_label after the generated code.</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="si">{0}</span><span class="s2">:</span>
<span class="s2">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">fin_label</span><span class="p">))</span>
<span class="c1"># We put an li t0, cardoffset in case it is greater than 2**11</span>
<span class="c1"># We use t0 because it is caller-saved</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="s2"> ld ra, 0(sp)</span>
<span class="s2"> ld fp, 8(sp)</span>
<span class="s2"> li t0, </span><span class="si">{0}</span>
<span class="s2"> add sp, sp, t0</span>
<span class="s2"> ret</span>
<span class="s2">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cardoffset</span><span class="p">))</span>
<span class="k">if</span> <span class="n">fin_div0</span><span class="p">:</span>
<span class="c1"># Add code for division by 0 at the end.</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="si">{0}</span><span class="s2">:</span>
<span class="s2"> la a0, </span><span class="si">{0}</span><span class="s2">_msg</span>
<span class="s2"> call println_string</span>
<span class="s2"> li a0, 1</span>
<span class="s2"> call exit</span>
<span class="s2">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">fdata</span><span class="o">.</span><span class="n">_label_div_by_zero</span><span class="p">))</span>
<span class="c1"># Add the data for the message of the division by 0</span>
<span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="si">{0}</span><span class="s2">_msg: .string &quot;Division by 0&quot;</span>
<span class="s2">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">fdata</span><span class="o">.</span><span class="n">_label_div_by_zero</span><span class="p">))</span>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>&#169; Copyright 2023, compil-lyon.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>