collab/polyglot-riscv-arm

what if the same machine code was valid riscv and arm asm

git clone https://git.julia.blue/collab/polyglot-riscv-arm

Jonathan Dönszelmannwebsite start885cc4e

main
11.1 KiB98 linesraw
1<?xml version="1.0" encoding="utf-8"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="insn.css"/><meta name="generator" content="iform.xsl"/><title>SUB (immediate, from PC) -- AArch32</title></head><body><table style="margin: 0 auto;"><tr><td><div class="topbar"><a href="index.html">Base Instructions</a></div></td><td><div class="topbar"><a href="fpsimdindex.html">SIMD&amp;FP Instructions</a></div></td><td><div class="topbar"><a href="a32_encindex.html">A32 Instructions by Encoding</a></div></td><td><div class="topbar"><a href="t32_encindex.html">T32 Instructions by Encoding</a></div></td><td><div class="topbar"><a href="shared_pseudocode.html">Shared Pseudocode</a></div></td><td><div class="topbar"><a href="notice.html">Proprietary Notice</a></div></td></tr></table><hr/><h2 class="instruction-section">SUB (immediate, from PC)</h2><p>Subtract from PC subtracts an immediate value from the Align(PC, 4) value to form a PC-relative address, and writes the result to the destination register.  Arm recommends that, where possible, software avoids using this alias.</p><p>
4        This is an alias of
5        <a href="adr.html">ADR</a>.
6        This means:
7      </p><ul><li>
8          The encodings in this description are named to match the encodings of
9          <a href="adr.html">ADR</a>.
10        </li><li>The description of <a href="adr.html">ADR</a> gives the operational pseudocode, any <span class="arm-defined-word">constrained unpredictable</span> behavior, and any operational information for this instruction.</li></ul>
11    <p class="desc">
12      It has encodings from the following instruction sets:
13       A32 (
14      <a href="#iclass_a2">A2</a>
15      )
16       and 
17       T32 (
18      <a href="#iclass_t2">T2</a>
19      )
20      .
21    </p>
22    <h3 class="classheading"><a id="iclass_a2"/>A2</h3><div class="regdiagram-32"><table class="regdiagram"><thead><tr><td>31</td><td>30</td><td>29</td><td>28</td><td>27</td><td>26</td><td>25</td><td>24</td><td>23</td><td>22</td><td>21</td><td>20</td><td>19</td><td>18</td><td>17</td><td>16</td><td>15</td><td>14</td><td>13</td><td>12</td><td>11</td><td>10</td><td>9</td><td>8</td><td>7</td><td>6</td><td>5</td><td>4</td><td>3</td><td>2</td><td>1</td><td>0</td></tr></thead><tbody><tr class="firstrow"><td colspan="4" class="lr">!= 1111</td><td class="l">0</td><td>0</td><td>1</td><td class="r">0</td><td class="l">0</td><td>1</td><td class="r">0</td><td class="lr">0</td><td class="l">1</td><td>1</td><td>1</td><td class="r">1</td><td colspan="4" class="lr">Rd</td><td colspan="12" class="lr">imm12</td></tr><tr class="secondrow"><td colspan="4" class="droppedname">cond</td><td colspan="4"/><td colspan="3"/><td/><td colspan="4"/><td colspan="4"/><td colspan="12"/></tr></tbody></table></div><div class="encoding"><h4 class="encoding">A2</h4><a id="SUB_ADR_A2"/><p class="asm-code">SUB{<a href="#sa_c" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;c&gt;</a>}{<a href="#sa_q" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;q&gt;</a>} <a href="#sa_rd_1" title="General-purpose destination register (field &quot;Rd&quot;)">&lt;Rd&gt;</a>, PC, #<a href="#sa_const" title="An immediate value">&lt;const&gt;</a></p><p class="equivto">
23      is equivalent to
24    </p>
25          <p class="asm-code"><a href="adr.html#ADR_A2">ADR</a>{<a href="#sa_c" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;c&gt;</a>}{<a href="#sa_q" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;q&gt;</a>} <a href="#sa_rd_1" title="General-purpose destination register (field &quot;Rd&quot;)">&lt;Rd&gt;</a>, <a href="#sa_label_2" title="The label of an instruction or literal data item whose address is to be loaded into {syntax{&lt;Rd&gt;}}">&lt;label&gt;</a></p>
26          <p class="equivto">
27          and is the preferred disassembly when
28          <span class="pseudocode">imm12 == '000000000000'</span>.
29        </p>
30        </div>
31    <h3 class="classheading"><a id="iclass_t2"/>T2</h3><div class="regdiagram-16x2"><table class="regdiagram"><thead><tr><td>15</td><td>14</td><td>13</td><td>12</td><td>11</td><td>10</td><td>9</td><td>8</td><td>7</td><td>6</td><td>5</td><td>4</td><td>3</td><td>2</td><td>1</td><td>0</td><td>15</td><td>14</td><td>13</td><td>12</td><td>11</td><td>10</td><td>9</td><td>8</td><td>7</td><td>6</td><td>5</td><td>4</td><td>3</td><td>2</td><td>1</td><td>0</td></tr></thead><tbody><tr class="firstrow"><td class="l">1</td><td>1</td><td>1</td><td>1</td><td class="r">0</td><td class="lr">i</td><td class="l">1</td><td class="r">0</td><td class="lr">1</td><td class="lr">0</td><td class="lr">1</td><td class="lr">0</td><td class="l">1</td><td>1</td><td>1</td><td class="r">1</td><td class="lr">0</td><td colspan="3" class="lr">imm3</td><td colspan="4" class="lr">Rd</td><td colspan="8" class="lr">imm8</td></tr></tbody></table></div><div class="encoding"><h4 class="encoding">T2</h4><a id="SUB_ADR_T2"/><p class="asm-code">SUB{<a href="#sa_c" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;c&gt;</a>}{<a href="#sa_q" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;q&gt;</a>} <a href="#sa_rd" title="General-purpose destination register (field &quot;Rd&quot;)">&lt;Rd&gt;</a>, PC, #<a href="#sa_imm12" title="12-bit unsigned immediate [0-4095] (field &quot;i:imm3:imm8&quot;)">&lt;imm12&gt;</a></p><p class="equivto">
32      is equivalent to
33    </p>
34          <p class="asm-code"><a href="adr.html#ADR_T2">ADR</a>{<a href="#sa_c" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;c&gt;</a>}{<a href="#sa_q" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;q&gt;</a>} <a href="#sa_rd" title="General-purpose destination register (field &quot;Rd&quot;)">&lt;Rd&gt;</a>, <a href="#sa_label_1" title="The label of an instruction or literal data item whose address is to be loaded into {syntax{&lt;Rd&gt;}}">&lt;label&gt;</a></p>
35          <p class="equivto">
36          and is the preferred disassembly when
37          <span class="pseudocode">i:imm3:imm8 == '000000000000'</span>.
38        </p>
39        </div>
40  <div class="encoding-notes"/><h3 class="explanations">Assembler Symbols</h3><div class="explanations"><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;c&gt;</td><td><a id="sa_c"/>
41        
42          <p class="aml">See <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="Babbefhf">Standard assembler syntax fields</a>.</p>
43        
44      </td></tr></table><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;q&gt;</td><td><a id="sa_q"/>
45        
46          <p class="aml">See <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="Babbefhf">Standard assembler syntax fields</a>.</p>
47        
48      </td></tr></table><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;Rd&gt;</td><td><a id="sa_rd_1"/>
49        
50          
51        
52        
53          <p class="aml">For encoding A2: is the general-purpose destination register, encoded in the "Rd" field. If the PC is used, the instruction is a branch to the address calculated by the operation. This is an interworking branch, see <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="BEICJFEH">Pseudocode description of operations on the AArch32 general-purpose registers and the PC</a>.</p>
54        
55      </td></tr><tr><td/><td><a id="sa_rd"/>
56        
57          
58        
59        
60          <p class="aml">For encoding T2: is the general-purpose destination register, encoded in the "Rd" field.</p>
61        
62      </td></tr></table><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;label&gt;</td><td><a id="sa_label_2"/>
63        
64          
65          
66        
67        
68          <p class="aml">For encoding A2: the label of an instruction or literal data item whose address is to be loaded into &lt;Rd&gt;. The assembler calculates the required value of the offset from the Align(PC, 4) value of the <span class="asm-code">ADR</span> instruction to this label.</p>
69          <p class="aml">If the offset is zero or positive, encoding A1 is used, with imm32 equal to the offset.</p>
70          <p class="aml">If the offset is negative, encoding A2 is used, with imm32 equal to the size of the offset. That is, the use of encoding A2 indicates that the required offset is minus the value of imm32.</p>
71          <p class="aml">Permitted values of the size of the offset are any of the constants described in <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="BABHDAJF">Modified immediate constants in A32 instructions</a>.</p>
72        
73      </td></tr><tr><td/><td><a id="sa_label_1"/>
74        
75          
76          
77        
78        
79          <p class="aml">For encoding T2: the label of an instruction or literal data item whose address is to be loaded into &lt;Rd&gt;. The assembler calculates the required value of the offset from the Align(PC, 4) value of the <span class="asm-code">ADR</span> instruction to this label.</p>
80          <p class="aml">If the offset is zero or positive, encoding T3 is used, with imm32 equal to the offset.</p>
81          <p class="aml">If the offset is negative, encoding T2 is used, with imm32 equal to the size of the offset. That is, the use of encoding T2 indicates that the required offset is minus the value of imm32.</p>
82          <p class="aml">Permitted values of the size of the offset are 0-4095.</p>
83        
84      </td></tr></table><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;imm12&gt;</td><td><a id="sa_imm12"/>
85        
86          <p class="aml">Is a 12-bit unsigned immediate, in the range 0 to 4095, encoded in the "i:imm3:imm8" field.</p>
87        
88      </td></tr></table><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;const&gt;</td><td><a id="sa_const"/>
89        
90          <p class="aml">An immediate value. See <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="BABHDAJF">Modified immediate constants in A32 instructions</a> for the range of values.</p>
91        
92      </td></tr></table></div><div class="syntax-notes"/><div class="alias_ps_section"><h3 class="pseudocode">Operation</h3><p>The description of <a href="adr.html">ADR</a> gives the operational pseudocode for this instruction.</p></div><hr/><table style="margin: 0 auto;"><tr><td><div class="topbar"><a href="index.html">Base Instructions</a></div></td><td><div class="topbar"><a href="fpsimdindex.html">SIMD&amp;FP Instructions</a></div></td><td><div class="topbar"><a href="a32_encindex.html">A32 Instructions by Encoding</a></div></td><td><div class="topbar"><a href="t32_encindex.html">T32 Instructions by Encoding</a></div></td><td><div class="topbar"><a href="shared_pseudocode.html">Shared Pseudocode</a></div></td><td><div class="topbar"><a href="notice.html">Proprietary Notice</a></div></td></tr></table><p class="versions">
93      Internal version only: isa v01_31, pseudocode v2024-09_rel
94      ; Build timestamp: 2024-09-26T13:26
95    </p><p class="copyconf">
96      Copyright © 2010-2024 Arm Limited or its affiliates. All rights reserved.
97      This document is Non-Confidential.
98    </p></body></html>