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
14.4 KiB125 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>AND, ANDS (immediate) -- 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">AND, ANDS (immediate)</h2>
4      <p class="aml">Bitwise AND (immediate) performs a bitwise AND of a register value and an immediate value, and writes the result to the destination register.</p>
5      <p class="aml">If the destination register is not the PC, the ANDS variant of the instruction updates the condition flags based on the result.</p>
6      <p class="aml">The field descriptions for &lt;Rd&gt; identify the encodings where the PC is permitted as the destination register. Arm deprecates any use of these encodings. However, when the destination register is the PC:</p>
7      <ul>
8        <li>The AND variant of the instruction 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>.</li>
9        <li>The ANDS variant of the instruction performs an exception return without the use of the stack. In this case:<ul><li>The PE branches to the address written to the PC, and restores <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="BEIDIGBH">PSTATE</a> from SPSR_&lt;current_mode&gt;.</li><li>The PE checks SPSR_&lt;current_mode&gt; for an illegal return event. See <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="CHDDDJDB">Illegal return events from AArch32 state</a>.</li><li>The instruction is <span class="arm-defined-word">undefined</span> in Hyp mode.</li><li>The instruction is <span class="arm-defined-word">constrained unpredictable</span> in User mode and System mode.</li></ul></li>
10      </ul>
11    
12    <p class="desc">
13      It has encodings from the following instruction sets:
14       A32 (
15      <a href="#iclass_a1">A1</a>
16      )
17       and 
18       T32 (
19      <a href="#iclass_t1">T1</a>
20      )
21      .
22    </p>
23    <h3 class="classheading"><a id="iclass_a1"/>A1</h3><p class="desc"/><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>0</td><td class="r">0</td><td class="lr">S</td><td colspan="4" class="lr">Rn</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">AND<span class="bitdiff"> (S == 0)</span></h4><a id="AND_i_A1"/><p class="asm-code">AND{<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_rn_1" title="General-purpose source register (field &quot;Rn&quot;)">&lt;Rn&gt;</a>, #<a href="#sa_const_1" title="An immediate value">&lt;const&gt;</a></p></div><div class="encoding"><h4 class="encoding">ANDS<span class="bitdiff"> (S == 1)</span></h4><a id="ANDS_i_A1"/><p class="asm-code">ANDS{<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_rn_1" title="General-purpose source register (field &quot;Rn&quot;)">&lt;Rn&gt;</a>, #<a href="#sa_const_1" title="An immediate value">&lt;const&gt;</a></p></div><p class="pseudocode">constant d = <a href="shared_pseudocode.html#impl-shared.UInt.1" title="function: integer UInt(bits(N) x)">UInt</a>(Rd);  constant n = <a href="shared_pseudocode.html#impl-shared.UInt.1" title="function: integer UInt(bits(N) x)">UInt</a>(Rn);  constant setflags = (S == '1');
24constant a32 = TRUE;
25constant bits(12) imm = imm12;</p>
26    <h3 class="classheading"><a id="iclass_t1"/>T1</h3><p class="desc"/><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="lr">0</td><td class="l">0</td><td>0</td><td>0</td><td class="r">0</td><td class="lr">S</td><td colspan="4" class="lr">Rn</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">AND<span class="bitdiff"> (S == 0)</span></h4><a id="AND_i_T1"/><p class="asm-code">AND{<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_rn" title="General-purpose source register (field &quot;Rn&quot;)">&lt;Rn&gt;</a>, #<a href="#sa_const" title="An immediate value">&lt;const&gt;</a></p></div><div class="encoding"><h4 class="encoding">ANDS<span class="bitdiff"> (S == 1 &amp;&amp; Rd != 1111)</span></h4><a id="ANDS_i_T1"/><p class="asm-code">ANDS{<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_rn" title="General-purpose source register (field &quot;Rn&quot;)">&lt;Rn&gt;</a>, #<a href="#sa_const" title="An immediate value">&lt;const&gt;</a></p></div><p class="pseudocode">if Rd == '1111' &amp;&amp; S == '1' then SEE "TST (immediate)";
27constant d = <a href="shared_pseudocode.html#impl-shared.UInt.1" title="function: integer UInt(bits(N) x)">UInt</a>(Rd); constant n = <a href="shared_pseudocode.html#impl-shared.UInt.1" title="function: integer UInt(bits(N) x)">UInt</a>(Rn); constant setflags = (S == '1'); constant a32 = FALSE;
28constant bits(12) imm = i:imm3:imm8;
29// Armv8-A removes UNPREDICTABLE for R13
30if (d == 15 &amp;&amp; !setflags) || n == 15 then UNPREDICTABLE;</p>
31  <div class="encoding-notes">
32      <p class="aml">For more information about the <span class="arm-defined-word">constrained unpredictable</span> behavior, see <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="CJAEGDJC">Architectural Constraints on UNPREDICTABLE behaviors</a>.</p>
33    </div><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"/>
34        
35          <p class="aml">See <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="Babbefhf">Standard assembler syntax fields</a>.</p>
36        
37      </td></tr></table><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;q&gt;</td><td><a id="sa_q"/>
38        
39          <p class="aml">See <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="Babbefhf">Standard assembler syntax fields</a>.</p>
40        
41      </td></tr></table><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;Rd&gt;</td><td><a id="sa_rd_1"/>
42        
43          
44          
45        
46        
47          <p class="aml">For encoding A1: is the general-purpose destination register, encoded in the "Rd" field. If omitted, this register is the same as &lt;Rn&gt;. Arm deprecates using the PC as the destination register, but if the PC is used:</p>
48          <ul>
49            <li>For the AND variant, 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>.</li>
50            <li>For the ANDS variant, the instruction performs an exception return, that restores <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="BEIDIGBH">PSTATE</a> from SPSR_&lt;current_mode&gt;.</li>
51          </ul>
52        
53      </td></tr><tr><td/><td><a id="sa_rd"/>
54        
55          
56          
57        
58        
59          <p class="aml">For encoding T1: is the general-purpose destination register, encoded in the "Rd" field. If omitted, this register is the same as &lt;Rn&gt;.</p>
60        
61      </td></tr></table><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;Rn&gt;</td><td><a id="sa_rn_1"/>
62        
63          
64          
65        
66        
67          <p class="aml">For encoding A1: is the general-purpose source register, encoded in the "Rn" field. The PC can be used, but this is deprecated.</p>
68        
69      </td></tr><tr><td/><td><a id="sa_rn"/>
70        
71          
72          
73        
74        
75          <p class="aml">For encoding T1: is the general-purpose source register, encoded in the "Rn" field.</p>
76        
77      </td></tr></table><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;const&gt;</td><td><a id="sa_const_1"/>
78        
79          
80          
81        
82        
83          <p class="aml">For encoding A1: 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>
84        
85      </td></tr><tr><td/><td><a id="sa_const"/>
86        
87          
88          
89        
90        
91          <p class="aml">For encoding T1: an immediate value. See <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="BABGHAGA">Modified immediate constants in T32 instructions</a> for the range of values.</p>
92        
93      </td></tr></table></div><div class="syntax-notes"/>
94    <div class="ps"><a id="execute"/><h3 class="pseudocode">Operation</h3>
95      <p class="pseudocode">if <a href="shared_pseudocode.html#impl-aarch32.ConditionPassed.0" title="function: boolean ConditionPassed()">ConditionPassed</a>() then
96    EncodingSpecificOperations();
97    constant (imm32, carry) = (if a32 then <a href="shared_pseudocode.html#impl-aarch32.A32ExpandImm_C.2" title="function: (bits(32), bit) A32ExpandImm_C(bits(12) imm12, bit carry_in)">A32ExpandImm_C</a>(imm, PSTATE.C)
98                               else <a href="shared_pseudocode.html#impl-aarch32.T32ExpandImm_C.2" title="function: (bits(32), bit) T32ExpandImm_C(bits(12) imm12, bit carry_in)">T32ExpandImm_C</a>(imm, PSTATE.C));
99    constant result = <a href="shared_pseudocode.html#impl-aarch32.R.read.1" title="accessor: bits(32) R[integer n]">R</a>[n] AND imm32;
100    if d == 15 then          // Can only occur for A32 encoding
101        if setflags then
102            <a href="shared_pseudocode.html#impl-aarch32.ALUExceptionReturn.1" title="function: ALUExceptionReturn(bits(32) address)">ALUExceptionReturn</a>(result);
103        else
104            <a href="shared_pseudocode.html#impl-aarch32.ALUWritePC.1" title="function: ALUWritePC(bits(32) address)">ALUWritePC</a>(result);
105    else
106        <a href="shared_pseudocode.html#impl-aarch32.R.write.1" title="accessor: R[integer n] = bits(32) value">R</a>[d] = result;
107        if setflags then
108            PSTATE.N = result&lt;31&gt;;
109            PSTATE.Z = <a href="shared_pseudocode.html#impl-shared.IsZeroBit.1" title="function: bit IsZeroBit(bits(N) x)">IsZeroBit</a>(result);
110            PSTATE.C = carry;
111            // PSTATE.V unchanged</p>
112    </div>
113  <h3>Operational information</h3>
114    <p class="aml">If CPSR.DIT is 1 and this instruction does not use R15 as either its source or destination:</p>
115    <ul>
116      <li>The execution time of this instruction is independent of:<ul><li>The values of the data supplied in any of its registers.</li><li>The values of the NZCV flags.</li></ul></li>
117      <li>The response of this instruction to asynchronous exceptions does not vary based on:<ul><li>The values of the data supplied in any of its registers.</li><li>The values of the NZCV flags.</li></ul></li>
118    </ul>
119  <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">
120      Internal version only: isa v01_31, pseudocode v2024-09_rel
121      ; Build timestamp: 2024-09-26T13:26
122    </p><p class="copyconf">
123      Copyright © 2010-2024 Arm Limited or its affiliates. All rights reserved.
124      This document is Non-Confidential.
125    </p></body></html>