<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" encoding="UTF-8" href="iform.xsl" version="1.0"?>
<!DOCTYPE instructionsection PUBLIC "-//ARM//DTD instructionsection //EN" "iform-p.dtd">
<!-- Copyright (c) 2010-2022 Arm Limited or its affiliates. All rights reserved. -->
<!-- This document is Non-Confidential. This document may only be used and distributed in accordance with the terms of the agreement entered into by Arm and the party that Arm delivered this document to. -->

<instructionsection id="ADR" title="ADR -- A64" type="instruction">
  <docvars>
    <docvar key="address-form" value="literal" />
    <docvar key="instr-class" value="general" />
    <docvar key="isa" value="A64" />
    <docvar key="mnemonic" value="ADR" />
    <docvar key="offset-type" value="off19s" />
  </docvars>
  <heading>ADR</heading>
  <desc>
    <brief>
      <para>Form PC-relative address</para>
    </brief>
    <authored>
      <para>Form PC-relative address adds an immediate value to the PC value to form a PC-relative address, and writes the result to the destination register.</para>
    </authored>
  </desc>
  <alias_list howmany="0"></alias_list>
  <classes>
    <iclass name="Literal" oneof="1" id="iclass_literal" no_encodings="1" isa="A64">
      <docvars>
        <docvar key="address-form" value="literal" />
        <docvar key="instr-class" value="general" />
        <docvar key="isa" value="A64" />
        <docvar key="mnemonic" value="ADR" />
        <docvar key="offset-type" value="off19s" />
      </docvars>
      <iclassintro count="1"></iclassintro>
      <regdiagram form="32" psname="aarch64/instrs/integer/arithmetic/address/pc-rel" tworows="1">
        <box hibit="31" name="op" usename="1" settings="1" psbits="x">
          <c>0</c>
        </box>
        <box hibit="30" width="2" name="immlo" usename="1">
          <c colspan="2"></c>
        </box>
        <box hibit="28" width="5" settings="5">
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="23" width="19" name="immhi" usename="1">
          <c colspan="19"></c>
        </box>
        <box hibit="4" width="5" name="Rd" usename="1">
          <c colspan="5"></c>
        </box>
      </regdiagram>
      <encoding name="ADR_only_pcreladdr" oneofinclass="1" oneof="1" label="">
        <docvars>
          <docvar key="address-form" value="literal" />
          <docvar key="instr-class" value="general" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="ADR" />
          <docvar key="offset-type" value="off19s" />
        </docvars>
        <asmtemplate><text>ADR  </text><a link="sa_xd" hover="64-bit general-purpose destination register (field &quot;Rd&quot;)">&lt;Xd&gt;</a><text>, </text><a link="sa_label" hover="Label whose address is to be calculated (field &quot;immhi:immlo&quot;)">&lt;label&gt;</a></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="aarch64/instrs/integer/arithmetic/address/pc-rel" mylink="aarch64.instrs.integer.arithmetic.address.pc-rel" enclabels="" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">integer d = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Rd);
boolean page = (op == '1');
bits(64) imm;

if page then
    imm = <a link="impl-shared.SignExtend.2" file="shared_pseudocode.xml" hover="function: bits(N) SignExtend(bits(M) x, integer N)">SignExtend</a>(immhi:immlo:<a link="impl-shared.Zeros.1" file="shared_pseudocode.xml" hover="function: bits(N) Zeros(integer N)">Zeros</a>(12), 64);
else
    imm = <a link="impl-shared.SignExtend.2" file="shared_pseudocode.xml" hover="function: bits(N) SignExtend(bits(M) x, integer N)">SignExtend</a>(immhi:immlo, 64);</pstext>
        </ps>
      </ps_section>
    </iclass>
  </classes>
  <explanations scope="all">
    <explanation enclist="ADR_only_pcreladdr" symboldefcount="1">
      <symbol link="sa_xd">&lt;Xd&gt;</symbol>
      <account encodedin="Rd">
        <intro>
          <para>Is the 64-bit name of the general-purpose destination register, encoded in the "Rd" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="ADR_only_pcreladdr" symboldefcount="1">
      <symbol link="sa_label">&lt;label&gt;</symbol>
      <account encodedin="immhi:immlo">
        <intro>
          <para>Is the program label whose address is to be calculated. Its offset from the address of this instruction, in the range +/-1MB, is encoded in "immhi:immlo".</para>
        </intro>
      </account>
    </explanation>
  </explanations>
  <ps_section howmany="1">
    <ps name="aarch64/instrs/integer/arithmetic/address/pc-rel" mylink="execute" enclabels="" sections="1" secttype="Operation">
      <pstext mayhavelinks="1" section="Execute" rep_section="execute">bits(64) base = <a link="impl-aarch64.PC.read.0" file="shared_pseudocode.xml" hover="accessor: bits(64) PC[]">PC</a>[];

if page then
    base&lt;11:0&gt; = <a link="impl-shared.Zeros.1" file="shared_pseudocode.xml" hover="function: bits(N) Zeros(integer N)">Zeros</a>(12);

<a link="impl-aarch64.X.write.2" file="shared_pseudocode.xml" hover="accessor: X[integer n, integer width] = bits(width) value">X</a>[d, 64] = base + imm;</pstext>
    </ps>
  </ps_section>
</instructionsection>
