67
AAP: An Altruistic Processor A reference Harvard architecture for embedded compiler development Simon Cook Jeremy Bennett Application Note 13. Issue 2.0 Publication date October 2015

AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

Embed Size (px)

Citation preview

Page 1: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

AAP: An Altruistic ProcessorA reference Harvard architecture for

embedded compiler development

Simon CookJeremy BennettApplication Note 13. Issue 2.0Publication date October 2015

Page 2: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

ii Copyright © 2015 Embecosm Limited

Legal NoticeThis work is licensed under the Creative Commons Attribution-ShareAlike 4.0 InternationalLicense. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0.

This license means you are free to:• Share—copy and redistribute the material in any medium or format;

• Adapt—remix, transform, and build upon the material;

for any purpose, even commercially.

The licensor cannot revoke these freedoms as long as you follow the license terms.

Under the following terms:• Attribution.—You must give appropriate credit, provide a link to the license, and

indicate if changes were made. You may do so in any reasonable manner, but not in anyway that suggests the licensor endorses you or your use.

• ShareAlike—If you remix, transform, or build upon the material, you must distributeyour contributions under the same license as the original.

• No additional restrictions—You may not apply legal terms or technological measuresthat legally restrict others from doing anything the license permits.

• Nothing in this license impairs or restricts the author's moral rights.

NoteYou do not have to comply with the license for elements of the material in the publicdomain or where your use is permitted by an applicable exception or limitation.

No warranties are given. The license may not give you all of the permissionsnecessary for your intended use. For example, other rights such as publicity,privacy, or moral rights may limit how you use the material.

Embecosm is the business name of Embecosm Limited, a private limited company registeredin England and Wales. Registration number 6577021.

Page 3: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

iii Copyright © 2015 Embecosm Limited

Table of Contents1. Introduction .................................................................................................................. 1

1.1. Revision History .................................................................................................. 12. Architecture Description ................................................................................................ 3

2.1. Basic architectural features ................................................................................ 32.2. Event Handling ................................................................................................... 42.3. NOP Behavior ....................................................................................................... 5

3. Instructions ................................................................................................................... 63.1. Notation .............................................................................................................. 6

3.1.1. Assembler Notation .................................................................................. 63.2. Instruction Format ............................................................................................. 63.3. Summary of Instructions .................................................................................... 8

3.3.1. 16-bit Instructions of AAP ........................................................................ 83.3.2. 32-bit Instructions of AAP ...................................................................... 10

3.4. Detailed Descriptions of 16-bit ALU Instructions .............................................. 143.4.1. NOP: No Operation ................................................................................. 143.4.2. ADD: Unsigned Add ............................................................................... 143.4.3. SUB: Unsigned Subtract ........................................................................ 143.4.4. AND: Bitwise AND .................................................................................. 153.4.5. OR: Bitwise OR ...................................................................................... 153.4.6. XOR: Bitwise Exclusive OR .................................................................... 153.4.7. ASR: Arithmetic Shift Right .................................................................... 163.4.8. LSL: Logical Shift Left ............................................................................ 163.4.9. LSR: Logical Shift Right ......................................................................... 173.4.10. MOV: Move Register to Register ............................................................ 173.4.11. ADDI: Unsigned Add Immediate ........................................................... 173.4.12. SUBI: Unsigned Subtract Immediate .................................................... 183.4.13. ASRI: Arithmetic Shift Right Immediate ................................................ 183.4.14. LSLI: Logical Shift Left Immediate ........................................................ 193.4.15. LSRI: Logical Shift Right Immediate ..................................................... 193.4.16. MOVI: Move Immediate to Register ....................................................... 20

3.5. Detailed Descriptions of 16-bit Load/Store Instructions .................................... 203.5.1. LDB: Indexed Load Byte ......................................................................... 203.5.2. LDW: Indexed Load Word ....................................................................... 203.5.3. LDB: Indexed Load Byte with Postincrement .......................................... 213.5.4. LDW: Indexed Load Word with Postincrement ........................................ 213.5.5. LDB: Indexed Load Byte with Predecrement ........................................... 223.5.6. LDW: Indexed Load Word with Predecrement ......................................... 223.5.7. STB: Indexed Store Byte ......................................................................... 233.5.8. STW: Indexed Store Word ....................................................................... 233.5.9. STB: Indexed Store Byte with Postincrement .......................................... 233.5.10. STW: Indexed Store Word with Postincrement ...................................... 243.5.11. STB: Indexed Store Byte with Predecrement ......................................... 243.5.12. STW: Indexed Store Word with Predecrement ....................................... 25

3.6. Detailed Descriptions of 16-bit Branch/Jump Instructions ............................... 253.6.1. BRA: Relative Branch ............................................................................. 253.6.2. BAL: Relative Branch and Link .............................................................. 263.6.3. BEQ: Relative Branch if Equal ............................................................... 263.6.4. BNE: Relative Branch if Not Equal ......................................................... 273.6.5. BLTS: Relative Branch if Signed Less Than ............................................ 273.6.6. BGTS: Relative Branch if Signed Greater Than ....................................... 283.6.7. BLTU: Relative Branch if Unsigned Less Than ........................................ 28

Page 4: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

iv Copyright © 2015 Embecosm Limited

3.6.8. BGTU: Relative Branch if Unsigned Greater Than ................................... 283.6.9. JMP: Absolute Jump .............................................................................. 293.6.10. JAL: Absolute Jump and Link .............................................................. 293.6.11. JEQ: Absolute Jump if Equal ............................................................... 303.6.12. JNE: Absolute Jump if Not Equal ......................................................... 303.6.13. JLTS: Absolute Jump if Signed Less Than ............................................ 313.6.14. JGTS: Absolute Jump if Signed Greater Than ....................................... 313.6.15. JLTU: Absolute Jump if Unsigned Less Than ....................................... 313.6.16. JGTU: Absolute Jump if Unsigned Greater Than .................................. 32

3.7. Detailed Descriptions of 16-bit Miscellaneous Instructions ................................ 323.7.1. RTE: Return from Exception .................................................................. 32

3.8. Detailed Descriptions of 32-bit ALU Instructions .............................................. 333.8.1. NOP: No Operation ................................................................................. 333.8.2. ADD: Unsigned Add ............................................................................... 333.8.3. SUB: Unsigned Subtract ........................................................................ 343.8.4. AND: Bitwise AND .................................................................................. 343.8.5. OR: Bitwise OR ...................................................................................... 343.8.6. XOR: Bitwise Exclusive OR .................................................................... 353.8.7. ASR: Arithmetic Shift Right .................................................................... 353.8.8. LSL: Logical Shift Left ............................................................................ 363.8.9. LSR: Logical Shift Right ......................................................................... 363.8.10. MOV: Move Register to Register ............................................................ 373.8.11. ADDI: Unsigned Add Immediate ........................................................... 373.8.12. SUBI: Unsigned Subtract Immediate .................................................... 373.8.13. ASRI: Arithmetic Shift Right Immediate ................................................ 383.8.14. LSLI: Logical Shift Left Immediate ........................................................ 383.8.15. LSRI: Logical Shift Right Immediate ..................................................... 393.8.16. MOVI: Move Immediate to Register ....................................................... 393.8.17. ADDC: Unsigned Add with Carry .......................................................... 403.8.18. SUBC: Unsigned Subtract with Carry ................................................... 403.8.19. ANDI: Bitwise AND Immediate .............................................................. 413.8.20. ORI: Bitwise OR immediate .................................................................. 413.8.21. XORI: Bitwise Exclusive OR Immediate ................................................ 41

3.9. Detailed Descriptions of 32-bit Load/Store Instructions .................................... 423.9.1. LDB: Indexed Load Byte ......................................................................... 423.9.2. LDW: Indexed Load Word ....................................................................... 423.9.3. LDB: Indexed Load Byte with Postincrement .......................................... 433.9.4. LDW: Indexed Load Word with Postincrement ........................................ 433.9.5. LDB: Indexed Load Byte with Predecrement ........................................... 443.9.6. LDW: Indexed Load Word with Predecrement ......................................... 443.9.7. STB: Indexed Store Byte ......................................................................... 443.9.8. STW: Indexed Store Word ....................................................................... 453.9.9. STB: Indexed Store Byte with Postincrement .......................................... 453.9.10. STW: Indexed Store Word with Postincrement ...................................... 463.9.11. STB: Indexed Store Byte with Predecrement ......................................... 463.9.12. STW: Indexed Store Word with Predecrement ....................................... 47

3.10. Detailed Descriptions of 32-bit Branch/Jump Instructions ............................. 473.10.1. BRA: Relative Branch ........................................................................... 473.10.2. BAL: Relative Branch and Link ............................................................ 483.10.3. BEQ: Relative Branch if Equal ............................................................. 483.10.4. BNE: Relative Branch if Not Equal ....................................................... 493.10.5. BLTS: Relative Branch if Signed Less Than .......................................... 493.10.6. BGTS: Relative Branch if Signed Greater Than ..................................... 50

Page 5: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

v Copyright © 2015 Embecosm Limited

3.10.7. BLTU: Relative Branch if Unsigned Less Than ...................................... 503.10.8. BGTU: Relative Branch if Unsigned Greater Than ................................. 513.10.9. JMP: Absolute Jump ............................................................................ 513.10.10. JAL: Absolute Jump and Link ............................................................ 523.10.11. JEQ: Absolute Jump if Equal ............................................................. 523.10.12. JNE: Absolute Jump if Not Equal ....................................................... 523.10.13. JLTS: Absolute Jump if Signed Less Than .......................................... 533.10.14. JGTS: Absolute Jump if Signed Greater Than ..................................... 533.10.15. JLTU: Absolute Jump if Unsigned Less Than ...................................... 543.10.16. JGTU: Absolute Jump if Unsigned Greater Than ................................ 543.10.17. JMPL: Absolute Jump Long ................................................................ 553.10.18. JALL: Absolute Jump Long and Link .................................................. 553.10.19. JEQL: Absolute Jump Long if Equal ................................................... 563.10.20. JNEL: Absolute Jump Long if Not Equal ............................................. 563.10.21. JLTSL: Absolute Jump Long if Signed Less Than ................................ 573.10.22. JGTSL: Absolute Jump Long if Signed Greater Than ........................... 573.10.23. JLTUL: Absolute Jump Long if Unsigned Less Than ........................... 583.10.24. JGTUL: Absolute Jump Long if Unsigned Greater Than ...................... 58

3.11. Detailed Descriptions of 32-bit Miscellaneous Instructions .............................. 594. ABI .............................................................................................................................. 60

4.1. Defined Registers .............................................................................................. 604.2. Calling Convention ............................................................................................ 60

Page 6: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

vi Copyright © 2015 Embecosm Limited

List of Figures2.1. AAP architecture ........................................................................................................ 33.1. AAP 16-bit instruction formats. .................................................................................. 73.2. AAP 32-bit instruction formats. .................................................................................. 8

Page 7: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

vii Copyright © 2015 Embecosm Limited

List of Tables3.1. 16-bit ALU instructions .............................................................................................. 83.2. 16-bit load/store instructions .................................................................................... 93.3. 16-bit branch/jump instructions ............................................................................... 93.4. Miscellaneous 16-bit instructions ............................................................................. 103.5. 32-bit ALU instructions ............................................................................................ 103.6. 32-bit load/store instructions .................................................................................. 113.7. 32-bit branch/jump instructions .............................................................................. 12

Page 8: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

1 Copyright © 2015 Embecosm Limited

Chapter 1. IntroductionAAP is a Harvard architecture specification designed for experimenting with various featuresin compiler back ends. In particular it has features that are common within small deeplyembedded systems, such as a dearth of registers, word address code memory and pointersthat will not fit in an integer.

It is also designed to be easy to use in demonstrations and education/training. This includeshardware and simulator implementation as well as the tool chain and library implementation.

The design is based on no processor in particular, although as an open hardware design, it isinspired by the OpenRISC and RISC-V projects. There are features drawn from a wide rangeof processors developed over the past 30 years. Indeed the branch-and-link operation goesback even further, to the IBM 360.

1.1. Revision HistoryRevision HistoryRevision 2.0 9 October 2015 Jeremy BennettIssue 2.0, which covers the entire ISA.Revision 1.9 8 October 2015 Jeremy BennettFinal draft before release 2.0. Adds some notation description and a chapter for thearchitecture description, which incorporates some of the old intro and the old chapter on NOPside effects.Revision 1.8 8 October 2015 Jeremy BennettAll 32-bit instructions described.Revision 1.7 8 September 2015 Jeremy BennettFirst batch of 32-bit ALU instruction described. Various typos fixed.Revision 1.6 8 September 2015 Jeremy BennettAll 16-bit instructions described. Encoding of JAL corrected in the summary. Rb used to storethe PC for all BAL and JAL instructions.Revision 1.5 8 September 2015 Jeremy Bennett16-bit ALU instruction details complete. Change opcode mnemonics for ALU instructions withconstant arguments. Off-by-one encoding for immediate shift values described.Revision 1.4 4 September 2015 Jeremy BennettStructure of detailed instruction descriptions refined. Most 16-bit ALU instructions nowdocumented.Revision 1.3 4 September 2015 Jeremy BennettAll instruction formats now shown. All summaries in new format.Revision 1.2 3 September 2015 Jeremy BennettFirst stage of improved formatting, using LibreOffice Impress to as the basis of the instructionformat diagrams for 32-bit instructions (generating SVG and PNG). Clearer summary ofinstructions used for 32-bit ALU instructions.Revision 1.1 18 July 2015 Jeremy BennettStart of revision process. Remove load/store double instructions. Use second opcode field of32-bit load/store as extra constant field. Make all load/store offsets signed. Make BAL use Rbrather than Ra to keep constant field contiguous.Revision 1.0 14 April 2015 Jeremy BennettBump release number to 1.0 for issue.Revision 0.9 14 April 2015 Jeremy BennettFirst public release outlining the architecture.Revision N/A 11 April 2015 Jeremy Bennett

Page 9: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

2 Copyright © 2015 Embecosm Limited

Correct encoding of 32-bit branches (4 more bits of offset). Correct NOP constant meanings.Matches server/simulator commit b179463.Revision N/A 8 April 2015 Jeremy BennettFull summary of all 16-bit and 32-bit instructions.Revision N/A 8 April 2015 Jeremy BennettUpdated preface in preparation for revised architecture.Revision N/A 6 April 2015 Simon CookInitial concept

Page 10: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

3 Copyright © 2015 Embecosm Limited

Chapter 2. Architecture DescriptionFigure 2.1 shows the overall structure of AAP.

Code Memories(words)

Data Memories (bytes)

0x0000

0xFFFF

0x0000

0xFFFFFF

ALU

R0

R63

4 - 64 Registers

R3R4

STATUS/PC

Figure 2.1.  AAP architecture

2.1. Basic architectural featuresThese are the key features of the AAP design.

16-bit RISCarchitecture

The core design sticks to the RISC principles of 3-address register-to-registeroperation, a small number of operations and a simple to implement data path.The fundamental data type is the 16-bit integer.

Configurablenumber ofregisters

Although 32/64-bit RISC architectures typically have 16 or more generalpurpose registers, small deeply embedded processors often have far fewer.This represents a significant compiler implementation challenge. To allowexploration of this area, AAP can be configured with between 4 and 64 16-bit registers.

Harvardmemorylayout

The basic architecture provides a 64k byte addressed data memory anda separate 16M word instruction memory. By requiring more than 16-bitsto address the instruction memory, the compiler writer can explore thechallenge of pointers which are larger than the native integer type.Deeply embedded systems often have very small memories, particularly fordata, so the size of memories can be configured.

Many architectures also provide more than two address spaces, often forspecial purposes. For example a small EEPROM alongside Flash memory, or

Page 11: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

4 Copyright © 2015 Embecosm Limited

the Special Purpose Register block of OpenRISC. AAP can support additionaladdress spaces, allowing support for multiple address spaces throughout thetool chain to be explored.

24-bitprogramcounter with8-bit statusregister

AAP requires a 24-bit program counter, which is held in a 32-bit register. Thetop bits of the program counter then form a status register. Jump instructionsignore these top 8 bits.At present only one status bit is defined, a carry flag to allow multipleprecision arithmetic.

16/32-bitinstructionencoding

A frequent feature of many architectures is to provide a subset of the mostcommonly used parts of the Instruction Set Architecture (ISA) in a shortencoding of 16-bits. Less common instructions are then encoded in 32-bits.Optimizing to use these shorter instructions, is particularly important forcompilers for embedded targets, where memory is at a premium. AAP providessuch a 16-bit subset with a 32-bit encoding of the full ISA. However it followsthe instruction chaining of RISC-V, so even longer instructions could becreated in the future.

The fields within each 16-bit instruction are fixed. A 32-bit instruction pairsup those fields to increase the number of instructions.

3-addresscode

AAP has stuck rigidly to the RISC principle of 3-address instructionsthroughout. Almost all instructions come in two variants, one where the thirdargument is a register, and one where the third argument is a constant.

No flagsfor flow ofcontrol

There are no flag registers indicating the results of operations for usein conditional jumps. Instead the operation is encoded within the jumpinstruction itself.There is an 8-bit status register as part of the program counter, whichincludes a carry flag. However this is not used for flow-of-control, but toenable multiple precision arithmetic.

Little endian The architecture is little-endian—the least significant byte of a word or doubleword is at the lowest address.The behavior for instruction memory is that one word is fetched, since it maybe a 16-bit instruction. If a second word is needed, then its fields are pairedwith the first instructions to give larger values for each field. This is done inlittle-endian fashion, i.e. the field from the second instruction forms the mostsignificant bits of the combined field.

No delayslots

Early RISC designs introduced the concept of a delay slot after branches.This avoided pipeline delays in branch processing. Implementations can nowavoid such pipeline delay, so like most modern architectures, AAP does nothave delay slots.

NOP withargumentfor simulatorcontrol

This idea is taken from OpenRISC. The NOP opcode includes fields to specify aregister and a constant. These can be used in both hardware and simulationto trigger side-effects.

2.2. Event HandlingEvents indirect through instructions in the first 256 (0x100) words of instruction memory.In general these should be 32-bit branch instructions, which means event handlers shouldreside in first or last 221 words of instruction memory.

At present the following event vector locations (word addresses) are defined

Page 12: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

5 Copyright © 2015 Embecosm Limited

0x00 Power-on reset.

0x02 Bus error

The event handling mechanism is still in development. In particular no location is yet definedfor the return address to be used by the RTE instruction (see Section 3.7.1).

2.3. NOP BehaviorThe NOP instruction takes an immediate argument which can be used to trigger certainbehavior in a simulator.

• 0 : Breakpoint

• 1 : Do nothing

• 2 : Exit with return code in Rd

• 3 : Write char in Rd to standard output.

• 4 : Write char in Rd to standard error.

• All other values: do nothing, but future behavior not guaranteed.

Page 13: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

6 Copyright © 2015 Embecosm Limited

Chapter 3. Instructions3.1. NotationIn the instruction descriptions below, the following notation is used.

Rd Destination register number "d" in the general registers.

Ra First source register number "a" in the general registers.

Rb Second source register number "b" in the general registers.

PC The program counter

I Unsigned immediate value

S Signed immediate value

dmem[i] Byte offset "i" in the data memory.

imem[i] Word offset "i" in the code memory.

carry The carry flag.

SignExt(x) The value "x" (which may be one of the above) sign extended as necessary.

Individual bits in the encodings are used as follows.

0 A zero bit.

1 A one bit.

dn Bit "n" of the destination register field.

an Bit "n" of the the first source register field.

bn Bit "n" of the the second source register field.

in Bit "n" of the the unsigned constant field.

sn Bit "n" of the the signed constant field.

3.1.1. Assembler Notation

The assembler generally follows standard GNU assembler conventions. Instructions take thefollowing form:

[label:] opcode [arguments]

There may be up to 3 arguments, separated by commas. Registers are indicted by R followedby a number. Constants and constant expressions may be preceded by # for clarity, but thisis not required. C style notation to indicate the base of constants, which defaults to decimal.

3.2. Instruction FormatThe 16-bit instruction formats are shown in Figure 3.1 and the 32-bit instruction formats inFigure 3.2.

Page 14: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

7 Copyright © 2015 Embecosm Limited

0 c1c

0o

3o

2o

1o

0d

2d

1d

0a

2a

1a

0b

2b

1b

0

0 c1c

0o

3o

2o

1o

0d

2d

1d

0a

2a

1a

0i2

i1

i0

0 c1c

0o

3o

2o

1o

0d

2d

1d

0i5

i4

i3

i2

i1

i0

c1c

0 Opcode classo

3...o

0 Opcoded

2...d

0 Destination registera

2...a

0 First source register

b2...b

0 Second source registerin...i

0 Unsigned immediate

Format

0 c1c

0o

3o

2o

1o

0d

2d

1d

0a

2a

1a

0s

2s

1s

0

sn...s

0 Unsigned immediate

0 c1c

0o

3o

2o

1o

0s

2s

1s

0a

2a

1a

0b

2b

1b

0

0 c1c

0o

3o

2o

1o

0s

5s

4s

3s

2s

1s

0b

2b

1b

06

5

4

3

2

1

0 c1c

0o

3o

2o

1o

0s

8s

7s

6s

5s

4s

3s

2s

1s

07

Figure 3.1.  AAP 16-bit instruction formats.

Page 15: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

8 Copyright © 2015 Embecosm Limited

1 c1c

0o

3o

2o

1o

0d

2d

1d

0a

2a

1a

0b

2b

1b

0 0 c3c

2o

7o

6o

5o

4d

5d

4d

3a

5a

4a

3b

5b

4b

3

First word (low address) Second word (high address)

1 c1c

0o

3o

2o

1o

0d

2d

1d

0a

2a

1a

0i2

i1

i0 0 c

3c

2o

6o

5o

4 0 d5d

4d

3a

5a

4a

3i5

i4

i3

1 c1c

0o

3o

2o

1o

0d

2d

1d

0a

2a

1a

0i2

i1

i0 0 c

3c

2i9

i8

i7

i6d

5d

4d

3a

5a

4a

3i5

i4

i3

1 c1c

0o

3o

2o

1o

0d

2d

1d

0i5

i4

i3

i2

i1

i0 0 c

3c

2o

7o

6o

5o

4d

5d

4d

3i11

i10

i9

i8

i7

i6

1 c1c

0o

3o

2o

1o

0d

2d

1d

0i5

i4

i3

i2

i1

i0 0 c

3c

2i15

i14

i13

i12

d5d

4d

3i11

i10

i9

i8

i7

i6

c3...c

0 Opcode classo

n...o

0 Opcoded

5...d

0 Destination registera

5...a

0 First source register

b5...b

0 Second source registerin...i

0 Unsigned immediate

Format

1 c1c

0o

3o

2o

1o

0d

2d

1d

0a

2a

1a

0i2

i1

i0 0 c

3c

2i8

i7

i6 1 d

5d

4d

3a

5a

4a

3i5

i4

i3

1 c1c

0o

3o

2o

1o

0d

2d

1d

0a

2a

1a

0s

2s

1s

0 0 c3c

2s

9s

8s

7s

6d

5d

4d

3a

5a

4a

3s

5s

4s

3

sn...s

0 Unsigned immediate

1 c1c

0o

3o

2o

1o

0s

2s

1s

0a

2a

1a

0b

2b

1b

0 0 c3c

2s

9s

8s

7s

6s

5s

4s

3a

5a

4a

3b

5b

4b

3

1 c1c

0o

3o

2o

1o

0s

5s

4s

3s

2s

1s

0b

2b

1b

0 0 c3c

2s

15s

14s

13s

12s

11s

10s

9s

8s

7s

6b

5b

4b

316

15

14

13

12

11

10

9

8

1 c1c

0o

3o

2o

1o

0s

8s

7s

6s

5s

4s

3s

2s

1s

0 0 c3c

2s

21s

20s

19s

18s

17s

16s

15s

14s

13s

12s

11s

10s

917

Figure 3.2.  AAP 32-bit instruction formats.

Longer instruction formats are possible by setting the top bit of the second word to 1. Byrepeating this, instructions of arbitrary length are possible.

3.3. Summary of Instructions

3.3.1. 16-bit Instructions of AAP• Table 3.1 lists all the 16-bit ALU instructions, which have class 00;

• Table 3.2 lists all the 16-bit load/store instructions, which have class 01;

• Table 3.3 lists all the 16-bit branch/jump instructions, which have class 10; and

• Table 3.4 lists all the 16-bit miscellaneous instructions, which have class 11.

Opcode Format Encoding DescriptionNOP Rd,I 5 0000000dddiiiiii No operation

Page 16: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

9 Copyright © 2015 Embecosm Limited

Opcode Format Encoding DescriptionADD Rd,Ra,Rb 1 0000001dddaaabbb Unsigned add

SUB Rd,Ra,Rb 1 0000010dddaaabbb Unsigned subtract

AND Rd,Ra,Rb 1 0000011dddaaabbb Bitwise AND

OR Rd,Ra,Rb 1 0000100dddaaabbb Bitwise OR

XOR Rd,Ra,Rb 1 0000101dddaaabbb Bitwise exclusive OR

ASR Rd,Ra,Rb 1 0000110dddaaabbb Arithmetic shift right

LSL Rd,Ra,Rb 1 0000111dddaaabbb Logical shift left

LSR Rd,Ra,Rb 1 0001000dddaaabbb Logical shift right

MOV Rd,Ra 1 0001001dddaaa000 Move register to register

ADDI Rd,Ra,#I 2 0001010dddaaaiii Unsigned add immediate

SUBI Rd,Ra,#I 2 0001011dddaaaiii Unsigned subtract immediate

ASRI Rd,Ra,#I 2 0001100dddaaaiii Arithmetic shift right immediate

LSLI Rd,Ra,#I 2 0001101dddaaaiii Logical shift left immediate

LSRI Rd,Ra,#I 2 0001110dddaaaiii Logical shift right immediate

MOVI Rd,#I 5 0001111dddiiiiii Move immediate to register

Table 3.1. 16-bit ALU instructions

Opcode Format Encoding DescriptionLDB Rd,(Ra,S) 4 0010000dddaaasss Indexed load byte

LDW Rd,(Ra,S) 4 0010100dddaaasss Indexed load word

LDB Rd,(Ra+,S) 4 0010001dddaaasss Indexed load byte with postincrement

LDW Rd,(Ra+,S) 4 0010101dddaaasss Indexed load word with postincrement

LDB Rd,(-Ra,S) 4 0010010dddaaasss Indexed load byte with predecrement

LDW Rd,(-Ra,S) 4 0010110dddaaasss Indexed load word with predecrement

STB (Rd,S),Ra 4 0011000dddaaasss Indexed store byte

STW (Rd,S),Ra 4 0011100dddaaasss Indexed store word

STB (Rd+,S),Ra 4 0011001dddaaasss Indexed store byte with postincrement

STW (Rd+,S),Ra 4 0011101dddaaasss Indexed store word with postincrement

STB (-Rd,S),Ra 4 0011010dddaaasss Indexed store byte with predecrement

STW (-Rd,S),Ra 4 0011110dddaaasss Indexed store word with predecrement

Table 3.2. 16-bit load/store instructions

Opcode Format Encoding DescriptionBRA S 7 0100000sssssssss Relative branch

BAL S,Rb 6 0100001ssssssbbb Relative branch and link

BEQ S,Ra,Rb 3 0100010sssaaabbb Relative branch if equal

BNE S,Ra,Rb 3 0100011sssaaabbb Relative branch if not equal

BLTS S,Ra,Rb 3 0100100sssaaabbb Relative branch if signed less than

Page 17: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

10 Copyright © 2015 Embecosm Limited

Opcode Format Encoding DescriptionBGTS S,Ra,Rb 3 0100101sssaaabbb Relative branch if signed greater than

BLTU S,Ra,Rb 3 0100110sssaaabbb Relative branch if unsigned less than

BGTU S,Ra,Rb 3 0100111sssaaabbbRelative branch if unsigned greaterthan

JMP Rd 1 0101000ddd000000 Absolute jump

JAL Rd,Rb 1 0101001ddd000bbb Absolute jump and link

JEQ Rd,Ra,Rb 1 0101010dddaaabbb Absolute jump if equal

JNE Rd,Ra,Rb 1 0101011dddaaabbb Absolute jump if not equal

JLTS Rd,Ra,Rb 1 0101100dddaaabbb Absolute jump if signed less than

JGTS Rd,Ra,Rb 1 0101101dddaaabbb Absolute jump if signed greater than

JLTU Rd,Ra,Rb 1 0101110dddaaabbb Absolute jump if unsigned less than

JGTU Rd,Ra,Rb 1 0101111dddaaabbb Absolute jump if unsigned greater than

Table 3.3. 16-bit branch/jump instructions

Opcode Format Encoding DescriptionRTE Rd 1 0110000ddd000000 Return from exception

Table 3.4. Miscellaneous 16-bit instructions

3.3.2. 32-bit Instructions of AAPIn the following list, the encoding is shown with the word at the lower address first.

• Table 3.5 lists all the 32-bit ALU instructions, which have class 00xx;

• Table 3.6 lists all the 32-bit load/store instructions, which have class 01xx;

• Table 3.7 lists all the 32-bit branch/jump instructions, which have class 10xx; and

• There are no 32-bit instructions in the miscellaneous class, but if there were, they wouldhave have class 11xx.

Opcode Format Encoding Description1000000dddiiiiii

NOP Rd,I 140000000dddiiiiii

No operation

1000001dddaaabbbADD Rd,Ra,Rb 8

0000000dddaaabbbUnsigned add

1000010dddaaabbbSUB Rd,Ra,Rb 8

0000000dddaaabbbUnsigned subtract

1000011dddaaabbbAND Rd,Ra,Rb 8

0000000dddaaabbbBitwise AND

1000100dddaaabbbOR Rd,Ra,Rb 8

0000000dddaaabbbBitwise OR

1000101dddaaabbbXOR Rd,Ra,Rb 8

0000000dddaaabbbBitwise exclusive OR

Page 18: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

11 Copyright © 2015 Embecosm Limited

Opcode Format Encoding Description1000110dddaaabbb

ASR Rd,Ra,Rb 80000000dddaaabbb

Arithmetic shift right

1000111dddaaabbbLSL Rd,Ra,Rb 8

0000000dddaaabbbLogical shift left

1001000dddaaabbbLSR Rd,Ra,Rb 8

0000000dddaaabbbLogical shift right

1001001dddaaa000MOV Rd,Ra 8

0000000dddaaa000Move register to register

1001010dddaaaiiiADDI Rd,Ra,I 11

000iiiidddaaaiiiUnsigned add immediate

1001011dddaaaiiiSUBI Rd,Ra,I 11

000iiiidddaaaiiiUnsigned subtract immediate

1001100dddaaaiiiASRI Rd,Ra,I 9

0000000dddaaaiiiArithmetic shift right immediate

1001101dddaaaiiiLSLI Rd,Ra,I 9

0000000dddaaaiiiLogical shift left immediate

1001110dddaaaiiiLSRI Rd,Ra,I 9

0000000dddaaaiiiLogical shift right immediate

1001111dddiiiiiiMOVI Rd,I 15

000iiiidddiiiiiiMove immediate to register

1000001dddaaabbbADDC Rd,Ra,Rb 8

0000001dddaaabbbAdd with carry

1000010dddaaabbbSUBC Rd,Ra,Rb 8

0000001dddaaabbbSubtract with carry

1000011dddaaaiiiANDI Rd,Ra,I 10

000iii1dddaaaiiiBitwise AND immediate

1000100dddaaaiiiORI Rd,Ra,I 10

000iii1dddaaaiiiBitwise OR immediate

1000101dddaaaiiiXORI Rd,Ra,I 10

000iii1dddaaaiiiBitwise exclusive OR immediate

Table 3.5. 32-bit ALU instructions

Opcode Format Encoding Description1010000dddaaasss

LDB Rd,(Ra,S) 13000ssssdddaaasss

Indexed load byte

1010100dddaaasssLDW Rd,(Ra,S) 13

000ssssdddaaasssIndexed load word

Page 19: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

12 Copyright © 2015 Embecosm Limited

Opcode Format Encoding Description1010001dddaaasss

LDB Rd,(Ra+,S) 13000ssssdddaaasss

Indexed load byte with postincrement

1010101dddaaasssLDW Rd,(Ra+,S) 13

000ssssdddaaasssIndexed load word with postincrement

1010010dddaaasssLDB Rd,(-Ra,S) 13

000ssssdddaaasssIndexed load byte with predecrement

1010110dddaaasssLDW Rd,(-Ra,S) 13

000ssssdddaaasssIndexed load word with predecrement

1011000dddaaasssSTB (Rd,S),Ra 13

000ssssdddaaasssIndexed store byte

1011100dddaaasssSTW (Rd,S),Ra 13

000ssssdddaaasssIndexed store word

1011001dddaaasssSTB (Rd+,S),Ra 13

000ssssdddaaasssIndexed store byte with postincrement

1011101dddaaasssSTW (Rd+,S),Ra 13

000ssssdddaaasssIndexed store word with postincrement

1011010dddaaasssSTB (-Rd,S),Ra 13

000ssssdddaaasssIndexed store byte with predecrement

1011111dddaaasssSTW (-Rd,S),Ra 13

000ssssdddaaasssIndexed store word with predecrement

Table 3.6. 32-bit load/store instructions

Opcode Format Encoding Description1100000sssssssss

BRA S 17000sssssssssssss

Relative branch

1100001ssssssbbbBAL S,Rb 16

000ssssssssssbbbRelative branch and link

1100010sssaaabbbBEQ S,Ra,Rb 12

000sssssssaaabbbRelative branch if equal

1100011sssaaabbbBNE S,Ra,Rb 12

000sssssssaaabbbRelative branch if not equal

1100100sssaaabbbBLTS S,Ra,Rb 12

000sssssssaaabbbRelative branch if signed less than

1100101sssaaabbbBGTS S,Ra,Rb 12

000sssssssaaabbbRelative branch if signed greater than

1100110sssaaabbbBLTU S,Ra,Rb 12

000sssssssaaabbbRelative branch if unsigned less than

Page 20: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

13 Copyright © 2015 Embecosm Limited

Opcode Format Encoding Description1100111sssaaabbb

BGTU S,Ra,Rb 12000sssssssaaabbb

Relative branch if unsigned greaterthan

1101000ddd000000JMP Rd 8

0000000ddd000000Absolute jump

1101001ddd000bbbJAL Rd,Rb 8

0000000ddd000bbbAbsolute jump and link

1101010dddaaabbbJEQ Rd,Ra,Rb 8

0000000dddaaabbbAbsolute jump if equal

1101011dddaaabbbJNE Rd,Ra,Rb 8

0000000dddaaabbbAbsolute jump if not equal

1101100dddaaabbbJLTS Rd,Ra,Rb 8

0000000dddaaabbbAbsolute jump if signed less than

1101101dddaaabbbJGTS Rd,Ra,Rb 8

0000000dddaaabbbAbsolute jump if signed greater than

1101110dddaaabbbJLTU Rd,Ra,Rb 8

0000000dddaaabbbAbsolute jump if unsigned less than

1101111dddaaabbbJGTU Rd,Ra,Rb 8

0000000dddaaabbbAbsolute jump if unsigned greater than

1101000ddd000000JMPL Rd 8

0000001ddd000000Absolute jump long

1101001ddd000bbbJALL Rd,Rb 8

0000001ddd000bbbAbsolute jump long and link

1101010dddaaabbbJEQL Rd,Ra,Rb 8

0000001dddaaabbbAbsolute jump long if equal

1101011dddaaabbbJNEL Rd,Ra,Rb 8

0000001dddaaabbbAbsolute jump long if not equal

1101100dddaaabbbJLTSL Rd,Ra,Rb 8

0000001dddaaabbbAbsolute jump long if signed less than

1101101dddaaabbbJGTSL Rd,Ra,Rb 8

0000001dddaaabbbAbsolute jump long if signed greaterthan

1101110dddaaabbbJLTUL Rd,Ra,Rb 8

0000001dddaaabbbAbsolute jump long if unsigned lessthan

1101111dddaaabbbJGTUL Rd,Ra,Rb 8

0000001dddaaabbbAbsolute jump if unsigned greater than

Table 3.7. 32-bit branch/jump instructions

Page 21: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

14 Copyright © 2015 Embecosm Limited

3.4. Detailed Descriptions of 16-bit ALU Instructions

3.4.1. NOP: No OperationEncoding (format 5):

0 0 0 0 0 0 0 d2 d1 d0 i5 i4 i3 i2 i1 i0

Syntax:

NOP Rd,I

Constraints:

d ≤ 7

I ≤ 63

Outcome:

PC ← PC + 1

Notes:

This opcode may trigger side-effects in implementations, depending on the value of I,particularly when simulating (see Section 2.3).All implementations should use d = 0, I = 0 as the break instruction for debugging, whichshould halt the processor.

All implementations should use d = 0, I = 1 as a true no-operation instruction.

The rationale behind this decision is that in an erroneous program, the most likely valueto be encountered as a random instruction is zero, which will stop the processor.

3.4.2. ADD: Unsigned AddEncoding (format 1):

0 0 0 0 0 0 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

ADD Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

Rd ← Ra + Rb

carry ← ( ( Ra + Rb ) ≥ 216 ) ? 1 : 0

PC ← PC + 1

3.4.3. SUB: Unsigned SubtractEncoding (format 1):

0 0 0 0 0 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

Page 22: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

15 Copyright © 2015 Embecosm Limited

SUB Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

Rd ← Ra - Rb

carry ← ( Rb > Ra ) ? 1 : 0

PC ← PC + 1

3.4.4. AND: Bitwise ANDEncoding (format 1):

0 0 0 0 0 1 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

AND Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

Rd ← Ra & Rb

PC ← PC + 1

3.4.5. OR: Bitwise OREncoding (format 1):

0 0 0 0 1 0 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

OR Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

Rd ← Ra | Rb

PC ← PC + 1

3.4.6. XOR: Bitwise Exclusive OREncoding (format 1):

Page 23: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

16 Copyright © 2015 Embecosm Limited

0 0 0 0 1 0 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

XOR Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

Rd ← Ra ^ Rb

PC ← PC + 1

3.4.7. ASR: Arithmetic Shift RightEncoding (format 1):

0 0 0 0 1 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

ASR Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

Rd ← ( Ra | ( carry << 16 ) ) >> Rb )

carry ← 0

PC ← PC + 1

Notes:

If Rb ≥ 17 the result in Rd will be zero.

The carry flag is always cleared, even if a shift of zero is specified.

3.4.8. LSL: Logical Shift LeftEncoding (format 1):

0 0 0 0 1 1 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

LSL Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

Page 24: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

17 Copyright © 2015 Embecosm Limited

d ≤ 7

Outcome:

Rd ← Ra << Rb

PC ← PC + 1

Notes:

If Rb ≥ 16 the result in Rd will be zero.

3.4.9. LSR: Logical Shift RightEncoding (format 1):

0 0 0 1 0 0 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

LSR Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

Rd ← Ra >> Rb

PC ← PC + 1

Notes:

If Rb ≥ 16 the result in Rd will be zero.

3.4.10. MOV: Move Register to RegisterEncoding (format 1):

0 0 0 1 0 0 1 d2 d1 d0 a2 a1 a0 0 0 0

Syntax:

MOV Rd,Ra

Constraints:

a ≤ 7

d ≤ 7

Outcome:

Rd ← Ra

PC ← PC + 1

3.4.11. ADDI: Unsigned Add ImmediateEncoding (format 2):

0 0 0 1 0 1 0 d2 d1 d0 a2 a1 a0 i2 i1 i0

Page 25: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

18 Copyright © 2015 Embecosm Limited

Syntax:

ADDI Rd,Ra,I

Constraints:

a ≤ 7

d ≤ 7

I ≤ 7

Outcome:

Rd ← Ra + I

carry ← ( ( Ra + I ) ≥ 216 ) ? 1 : 0

PC ← PC + 1

Notes:

Adding constant zero can be used to clear the carry flag.

3.4.12. SUBI: Unsigned Subtract ImmediateEncoding (format 2):

0 0 0 1 0 1 1 d2 d1 d0 a2 a1 a0 i2 i1 i0

Syntax:

SUBI Rd,Ra,I

Constraints:

a ≤ 7

d ≤ 7

I ≤ 7

Outcome:

Rd ← Ra - I

carry ← ( I > Ra ) ? 1 : 0

PC ← PC + 1

3.4.13. ASRI: Arithmetic Shift Right ImmediateEncoding (format 2):

0 0 0 1 1 0 0 d2 d1 d0 a2 a1 a0 i2 i1 i0

Syntax:

ASRI Rd,Ra,I

Constraints:

a ≤ 7

d ≤ 7

1 ≤ I ≤ 8

Outcome:

Page 26: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

19 Copyright © 2015 Embecosm Limited

Rd ← ( Ra | ( carry << 16 ) ) >> I )

carry ← 0

PC ← PC + 1

Notes:

The shift is encoded with a value 1 less than specified (i.e. a shift of 1 is encoded as 0002.The rationale is that shifting by zero is pointless. It is not needed to clear the carry flag,since there are other ways of clearing the it (for example adding constant zero).

3.4.14. LSLI: Logical Shift Left ImmediateEncoding (format 2):

0 0 0 1 1 0 1 d2 d1 d0 a2 a1 a0 i2 i1 i0

Syntax:

LSLI Rd,Ra,I

Constraints:

a ≤ 7

d ≤ 7

1 ≤ I ≤ 8

Outcome:

Rd ← Ra << I

PC ← PC + 1

Notes:

The shift is encoded with a value 1 less than specified (i.e. a shift of 1 is encoded as 0002.The rationale is that shifting by zero is pointless. It is not needed to clear the carry flag,since there are other ways of clearing the it (for example adding constant zero).

3.4.15. LSRI: Logical Shift Right ImmediateEncoding (format 2):

0 0 0 1 1 1 0 d2 d1 d0 a2 a1 a0 i2 i1 i0

Syntax:

LSRI Rd,Ra,I

Constraints:

a ≤ 7

d ≤ 7

1 ≤ I ≤ 8

Outcome:

Rd ← Ra >> I

PC ← PC + 1

Notes:

Page 27: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

20 Copyright © 2015 Embecosm Limited

The shift is encoded with a value 1 less than specified (i.e. a shift of 1 is encoded as 0002.The rationale is that shifting by zero is pointless. It is not needed to clear the carry flag,since there are other ways of clearing the it (for example adding constant zero).

3.4.16. MOVI: Move Immediate to RegisterEncoding (format 5):

0 0 0 1 1 1 1 d2 d1 d0 i5 i4 i3 i2 i1 i0

Syntax:

MOVI Rd,I

Constraints:

d ≤ 7

I ≤ 63

Outcome:

Rd ← I

PC ← PC + 1

3.5. Detailed Descriptions of 16-bit Load/Store Instructions

3.5.1. LDB: Indexed Load ByteEncoding (format 4):

0 0 1 0 0 0 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

Syntax:

LDB Rd,(Ra,S)

Constraints:

d ≤ 7

-4 ≤ S ≤ 3

Outcome:

Rd ← dmem[Ra + SignExt(S)]

PC ← PC + 1

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.5.2. LDW: Indexed Load WordEncoding (format 4):

0 0 1 0 1 0 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

Syntax:

LDW Rd,(Ra,S)

Constraints:

Page 28: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

21 Copyright © 2015 Embecosm Limited

d ≤ 7

-4 ≤ S ≤ 3

Outcome:

Rd ← dmem [Ra + SignExt(S)] | (dmem[Ra + SignExt(S) + 1] << 8)

PC ← PC + 1

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.5.3. LDB: Indexed Load Byte with PostincrementEncoding (format 4):

0 0 1 0 0 0 1 d2 d1 d0 a2 a1 a0 s2 s1 s0

Syntax:

LDB Rd,(Ra+,S)

Constraints:

d ≤ 7

-4 ≤ S ≤ 3

Outcome:

Rd ← dmem[Ra + SignExt(S)]

Ra ← Ra + 1

PC ← PC + 1

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.5.4. LDW: Indexed Load Word with PostincrementEncoding (format 4):

0 0 1 0 1 0 1 d2 d1 d0 a2 a1 a0 s2 s1 s0

Syntax:

LDW Rd,(Ra+,S)

Constraints:

d ≤ 7

-4 ≤ S ≤ 3

Outcome:

Rd ← dmem[Ra + SignExt(S)] | (dmem[Ra + SignExt(S) + 1] << 8)

Ra ← Ra + 2

PC ← PC + 1

Notes:

Page 29: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

22 Copyright © 2015 Embecosm Limited

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.5.5. LDB: Indexed Load Byte with PredecrementEncoding (format 4):

0 0 1 0 0 1 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

Syntax:

LDB Rd,(-Ra,S)

Constraints:

d ≤ 7

-4 ≤ S ≤ 3

Outcome:

Ra ← Ra - 1

Rd ← dmem[Ra + SignExt(S)]

PC ← PC + 1

Notes:

For the avoidance of doubt, the decrement of Ra is carried out before Ra is used tocompute the address for loading.

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.5.6. LDW: Indexed Load Word with PredecrementEncoding (format 4):

0 0 1 0 1 1 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

Syntax:

LDW Rd,(-Ra,S)

Constraints:

d ≤ 7

-4 ≤ S ≤ 3

Outcome:

Ra ← Ra - 2

Rd ← dmem[Ra + SignExt(S)] | (dmem[Ra + SignExt(S) + 1] << 8)

PC ← PC + 1

Notes:

For the avoidance of doubt, the decrement of Ra is carried out before Ra is used tocompute the address for loading.

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

Page 30: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

23 Copyright © 2015 Embecosm Limited

3.5.7. STB: Indexed Store ByteEncoding (format 4):

0 0 1 1 0 0 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

Syntax:

STB (Rd,S),Ra

Constraints:

d ≤ 7

-4 ≤ S ≤ 3

Outcome:

dmem[Rd + SignExt(S)] ← (Ra & 255)

PC ← PC + 1

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.5.8. STW: Indexed Store WordEncoding (format 4):

0 0 1 1 1 0 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

Syntax:

STW (Rd,S),Ra

Constraints:

d ≤ 7

-4 ≤ S ≤ 3

Outcome:

dmem[Rd + SignExt(S)] ← (Ra & 255)

dmem[Rd + SignExt(S) + 1] ← (Ra >> 8)

PC ← PC + 1

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.5.9. STB: Indexed Store Byte with PostincrementEncoding (format 4):

0 0 1 1 0 0 1 d2 d1 d0 a2 a1 a0 s2 s1 s0

Syntax:

STB (Rd+,S),Ra

Constraints:

Page 31: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

24 Copyright © 2015 Embecosm Limited

d ≤ 7

-4 ≤ S ≤ 3

Outcome:

dmem[Rd + SignExt(S)] ← (Ra & 255)

Ra ← Ra + 1

PC ← PC + 1

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.5.10. STW: Indexed Store Word with PostincrementEncoding (format 4):

0 0 1 1 1 0 1 d2 d1 d0 a2 a1 a0 s2 s1 s0

Syntax:

STW (Rd+,S),Ra

Constraints:

d ≤ 7

-4 ≤ S ≤ 3

Outcome:

dmem[Rd + SignExt(S)] ← (Ra & 255)

dmem[Rd + SignExt(S) + 1] ← (Ra >> 8)

Ra ← Ra + 2

PC ← PC + 1

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.5.11. STB: Indexed Store Byte with PredecrementEncoding (format 4):

0 0 1 1 0 1 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

Syntax:

STB (-Rd,S),Ra

Constraints:

d ≤ 7

-4 ≤ S ≤ 3

Outcome:

Ra ← Ra - 1

Page 32: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

25 Copyright © 2015 Embecosm Limited

dmem[Rd + SignExt(S)] ← (Ra & 255)

PC ← PC + 1

Notes:

For the avoidance of doubt, the decrement of Ra is carried out before Ra is used tocompute the address for loading.

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.5.12. STW: Indexed Store Word with PredecrementEncoding (format 4):

0 0 1 1 1 1 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

Syntax:

STW (-Rd,S),Ra

Constraints:

d ≤ 7

-4 ≤ S ≤ 3

Outcome:

Ra ← Ra - 2

dmem[Rd + SignExt(S)] ← (Ra & 255)

dmem[Rd + SignExt(S) + 1] ← (Ra >> 8)

PC ← PC + 1

Notes:

For the avoidance of doubt, the decrement of Ra is carried out before Ra is used tocompute the address for loading.

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.6. Detailed Descriptions of 16-bit Branch/Jump InstructionsNoteThe only branch/jump comparisons provided are for "equal", "not equal", "lessthan" and "greater than". Branch/jump comparisons for "less than or equal" and"greater than or equal" can be provided by using "greater than" and "less than"respectively in the opposite direction."

Purists will point out that this reduces the opportunity for branch prediction andpipeline preservation. However the limited instruction space means not all opcodescan be provided.

3.6.1. BRA: Relative BranchEncoding (format 7):

0 1 0 0 0 0 0 s8 s7 s6 s5 s4 s3 s2 s1 s0

Syntax:

Page 33: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

26 Copyright © 2015 Embecosm Limited

BRA S

Constraints:

-256 ≤ S ≤ 255

Outcome:

PC ← PC + SignExt(S)

Notes:

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.6.2. BAL: Relative Branch and LinkEncoding (format 6):

0 1 0 0 0 0 1 s5 s4 s3 s2 s1 s0 b2 b1 b0

Syntax:

BAL S,Rb

Constraints:

b ≤ 7

-32 ≤ S ≤ 31

Outcome:

Rb ← PC + 1

PC ← PC + SignExt(S)

Notes:

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.6.3. BEQ: Relative Branch if EqualEncoding (format 3):

0 1 0 0 0 1 0 s2 s1 s0 a2 a1 a0 b2 b1 b0

Syntax:

BEQ S,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

-4 ≤ S ≤ 3

Outcome:

PC ← (Ra = Rb) ? PC + SignExt(S) : PC + 1

Page 34: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

27 Copyright © 2015 Embecosm Limited

Notes:

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.6.4. BNE: Relative Branch if Not EqualEncoding (format 3):

0 1 0 0 0 1 1 s2 s1 s0 a2 a1 a0 b2 b1 b0

Syntax:

BNE S,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

-4 ≤ S ≤ 3

Outcome:

PC ← (Ra ≠ Rb) ? PC + SignExt(S) : PC + 1

Notes:

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.6.5. BLTS: Relative Branch if Signed Less ThanEncoding (format 3):

0 1 0 0 1 0 0 s2 s1 s0 a2 a1 a0 b2 b1 b0

Syntax:

BLTS S,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

-4 ≤ S ≤ 3

Outcome:

PC ← (Ra < Rb) ? PC + SignExt(S) : PC + 1

Notes:

The comparison between Ra and Rb is a signed comparison, where the contents of eachregister is treated as a 2's-complement signed number.

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

Page 35: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

28 Copyright © 2015 Embecosm Limited

3.6.6. BGTS: Relative Branch if Signed Greater ThanEncoding (format 3):

0 1 0 0 1 0 1 s2 s1 s0 a2 a1 a0 b2 b1 b0

Syntax:

BGTS S,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

-4 ≤ S ≤ 3

Outcome:

PC ← (Ra > Rb) ? PC + SignExt(S) : PC + 1

Notes:

The comparison between Ra and Rb is a signed comparison, where the contents of eachregister is treated as a 2's-complement signed number.

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.6.7. BLTU: Relative Branch if Unsigned Less ThanEncoding (format 3):

0 1 0 0 1 1 0 s2 s1 s0 a2 a1 a0 b2 b1 b0

Syntax:

BLTU S,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

-4 ≤ S ≤ 3

Outcome:

PC ← (Ra < Rb) ? PC + SignExt(S) : PC + 1

Notes:

The comparison between Ra and Rb is an unsigned comparison.

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.6.8. BGTU: Relative Branch if Unsigned Greater ThanEncoding (format 3):

0 1 0 0 1 1 1 s2 s1 s0 a2 a1 a0 b2 b1 b0

Page 36: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

29 Copyright © 2015 Embecosm Limited

Syntax:

BGTU S,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

-4 ≤ S ≤ 3

Outcome:

PC ← (Ra > Rb) ? PC + SignExt(S) : PC + 1

Notes:

The comparison between Ra and Rb is an unsigned comparison.

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.6.9. JMP: Absolute JumpEncoding (format 1):

0 1 0 1 0 0 0 d2 d1 d0 0 0 0 0 0 0

Syntax:

JMP Rd

Constraints:

d ≤ 7

Outcome:

PC ← Rd

Notes:

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jumping to a non-existent location will trigger a bus error exception.

3.6.10. JAL: Absolute Jump and LinkEncoding (format 1):

0 1 0 1 0 0 1 d2 d1 d0 0 0 0 b2 b1 b0

Syntax:

JAL Rd,Rb

Constraints:

b ≤ 7

d ≤ 7

Outcome:

Page 37: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

30 Copyright © 2015 Embecosm Limited

Rb ← PC + 1

PC ← Rd

Notes:

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jumping to a non-existent location will trigger a bus error exception.

3.6.11. JEQ: Absolute Jump if EqualEncoding (format 1):

0 1 0 1 0 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

JEQ Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

PC ← (Ra = Rb) ? Rd : PC + 1

Notes:

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.6.12. JNE: Absolute Jump if Not EqualEncoding (format 1):

0 1 0 1 0 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

JNE Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

PC ← (Ra ≠ Rb) ? Rd : PC + 1

Notes:

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

Page 38: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

31 Copyright © 2015 Embecosm Limited

3.6.13. JLTS: Absolute Jump if Signed Less ThanEncoding (format 1):

0 1 0 1 1 0 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

JLTS Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

PC ← (Ra < Rb) ? Rd : PC + 1

Notes:

The comparison between Ra and Rb is a signed comparison, where the contents of eachregister is treated as a 2's-complement signed number.

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.6.14. JGTS: Absolute Jump if Signed Greater ThanEncoding (format 1):

0 1 0 1 1 0 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

JGTS Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

PC ← (Ra > Rb) ? Rd : PC + 1

Notes:

The comparison between Ra and Rb is a signed comparison, where the contents of eachregister is treated as a 2's-complement signed number.

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.6.15. JLTU: Absolute Jump if Unsigned Less ThanEncoding (format 1):

Page 39: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

32 Copyright © 2015 Embecosm Limited

0 1 0 1 1 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

JLTU Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

PC ← (Ra < Rb) ? Rd : PC + 1

Notes:

The comparison between Ra and Rb is an unsigned comparison.

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.6.16. JGTU: Absolute Jump if Unsigned Greater ThanEncoding (format 1):

0 1 0 1 1 1 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

Syntax:

JGTU Rd,Ra,Rb

Constraints:

a ≤ 7

b ≤ 7

d ≤ 7

Outcome:

PC ← (Ra > Rb) ? Rd : PC + 1

Notes:

The comparison between Ra and Rb is an unsigned comparison.

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.7. Detailed Descriptions of 16-bit Miscellaneous Instructions

3.7.1. RTE: Return from ExceptionEncoding (format 1):

0 1 1 0 0 0 0 d2 d1 d0 0 0 0 0 0 0

Syntax:

Page 40: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

33 Copyright © 2015 Embecosm Limited

RTE Rd

Constraints:

d ≤ 7

Outcome:

PC ← Rd

Notes:

This opcode is not fully defined, pending agreement on the exception mechanism for AAP.

3.8. Detailed Descriptions of 32-bit ALU InstructionsAt this time, this section is incomplete.

3.8.1. NOP: No OperationEncoding (format 14, first word at lower address):

1 0 0 0 0 0 0 d2 d1 d0 i5 i4 i3 i2 i1 i0

0 0 0 0 0 0 0 d5 d4 d3 i11 i10 i9 i8 i7 i6

Syntax:

NOP Rd,I

Constraints:

d ≤ 63

I ≤ 4095

Outcome:

PC ← PC + 1

Notes:

This opcode may trigger side-effects in implementations, depending on the value of I,particularly when simulating (see Section 2.3).

There are no conventions for any values of d or I for the 32-bit version of NOP.

3.8.2. ADD: Unsigned AddEncoding (format 8, first word at lower address):

1 0 0 0 0 0 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

ADD Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Page 41: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

34 Copyright © 2015 Embecosm Limited

Outcome:

Rd ← Ra + Rb

carry ← ( ( Ra + Rb ) ≥ 216 ) ? 1 : 0

PC ← PC + 2

3.8.3. SUB: Unsigned SubtractEncoding (format 8, first word at lower address):

1 0 0 0 0 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

SUB Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

Rd ← Ra - Rb

carry ← ( Rb > Ra ) ? 1 : 0

PC ← PC + 2

3.8.4. AND: Bitwise ANDEncoding (format 8, first word at lower address):

1 0 0 0 0 1 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

AND Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

Rd ← Ra & Rb

PC ← PC + 2

3.8.5. OR: Bitwise OREncoding (format 8, first word at lower address):

1 0 0 0 1 0 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

Page 42: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

35 Copyright © 2015 Embecosm Limited

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

OR Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

Rd ← Ra | Rb

PC ← PC + 2

3.8.6. XOR: Bitwise Exclusive OREncoding (format 8, first word at lower address):

1 0 0 0 1 0 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

XOR Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

Rd ← Ra ^ Rb

PC ← PC + 2

3.8.7. ASR: Arithmetic Shift RightEncoding (format 8, first word at lower address):

1 0 0 0 1 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

ASR Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

Page 43: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

36 Copyright © 2015 Embecosm Limited

Rd ← ( Ra | ( carry << 16 ) ) >> Rb )

carry ← 0

PC ← PC + 2

Notes:

If Rb ≥ 17 the result in Rd will be zero.

The carry flag is always cleared, even if a shift of zero is specified.

3.8.8. LSL: Logical Shift LeftEncoding (format 8, first word at lower address):

1 0 0 0 1 1 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

LSL Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

Rd ← Ra << Rb

PC ← PC + 2

Notes:

If Rb ≥ 16 the result in Rd will be zero.

3.8.9. LSR: Logical Shift RightEncoding (format 8, first word at lower address):

1 0 0 1 0 0 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

LSR Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

Rd ← Ra >> Rb

PC ← PC + 2

Page 44: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

37 Copyright © 2015 Embecosm Limited

Notes:

If Rb ≥ 16 the result in Rd will be zero.

3.8.10. MOV: Move Register to RegisterEncoding (format 8, first word at lower address):

1 0 0 1 0 0 1 d2 d1 d0 a2 a1 a0 0 0 0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 0 0 0

Syntax:

MOV Rd,Ra

Constraints:

a ≤ 63

d ≤ 63

Outcome:

Rd ← Ra

PC ← PC + 2

3.8.11. ADDI: Unsigned Add ImmediateEncoding (format 11, first word at lower address):

1 0 0 1 0 1 0 d2 d1 d0 a2 a1 a0 i2 i1 i0

0 0 0 i9 i8 i7 i6 d5 d4 d3 a5 a4 a3 i5 i4 i3

Syntax:

ADDI Rd,Ra,I

Constraints:

a ≤ 63

d ≤ 63

I ≤ 63

Outcome:

Rd ← Ra + I

carry ← ( ( Ra + I ) ≥ 216 ) ? 1 : 0

PC ← PC + 2

Notes:

Adding constant zero can be used to clear the carry flag.

3.8.12. SUBI: Unsigned Subtract ImmediateEncoding (format 11, first word at lower address):

1 0 0 1 0 1 1 d2 d1 d0 a2 a1 a0 i2 i1 i0

0 0 0 i9 i8 i7 i6 d5 d4 d3 a5 a4 a3 i5 i4 i3

Page 45: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

38 Copyright © 2015 Embecosm Limited

Syntax:

SUBI Rd,Ra,I

Constraints:

a ≤ 63

d ≤ 63

I ≤ 63

Outcome:

Rd ← Ra - I

carry ← ( I > Ra ) ? 1 : 0

PC ← PC + 2

3.8.13. ASRI: Arithmetic Shift Right ImmediateEncoding (format 9, first word at lower address):

1 0 0 1 1 0 0 d2 d1 d0 a2 a1 a0 i2 i1 i0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 i5 i4 i3

Syntax:

ASRI Rd,Ra,I

Constraints:

a ≤ 63

d ≤ 63

1 ≤ I ≤ 64

Outcome:

Rd ← ( Ra | ( carry << 16 ) ) >> I )

carry ← 0

PC ← PC + 2

Notes:

If I ≥ 17 the result in Rd will be zero.

The shift is encoded with a value 1 less than specified (i.e. a shift of 1 is encoded as0000002. The rationale is that shifting by zero is pointless. It is not needed to clear thecarry flag, since there are other ways of clearing the it (for example adding constant zero).

3.8.14. LSLI: Logical Shift Left ImmediateEncoding (format 9, first word at lower address):

1 0 0 1 1 0 1 d2 d1 d0 a2 a1 a0 i2 i1 i0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 i5 i4 i3

Syntax:

LSLI Rd,Ra,I

Page 46: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

39 Copyright © 2015 Embecosm Limited

Constraints:

a ≤ 63

d ≤ 63

1 ≤ I ≤ 64

Outcome:

Rd ← Ra << I

PC ← PC + 2

Notes:

If I ≥ 16 the result in Rd will be zero.

The shift is encoded with a value 1 less than specified (i.e. a shift of 1 is encoded as0000002. The rationale is that shifting by zero is pointless. It is not needed to clear thecarry flag, since there are other ways of clearing the it (for example adding constant zero).

3.8.15. LSRI: Logical Shift Right ImmediateEncoding (format 9, first word at lower address):

1 0 0 1 1 1 0 d2 d1 d0 a2 a1 a0 i2 i1 i0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 i5 i4 i3

Syntax:

LSRI Rd,Ra,I

Constraints:

a ≤ 63

d ≤ 63

1 ≤ I ≤ 64

Outcome:

Rd ← Ra >> I

PC ← PC + 2

Notes:

If I ≥ 16 the result in Rd will be zero.

The shift is encoded with a value 1 less than specified (i.e. a shift of 1 is encoded as0000002. The rationale is that shifting by zero is pointless. It is not needed to clear thecarry flag, since there are other ways of clearing the it (for example adding constant zero).

3.8.16. MOVI: Move Immediate to RegisterEncoding (format 15, first word at lower address):

1 0 0 1 1 1 1 d2 d1 d0 i5 i4 i3 i2 i1 i0

0 0 0 i15 i14 i13 i12 d5 d4 d3 i11 i10 i9 i8 i7 i6

Syntax:

MOVI Rd,I

Page 47: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

40 Copyright © 2015 Embecosm Limited

Constraints:

d ≤ 63

I ≤ 65535

Outcome:

Rd ← I

PC ← PC + 2

3.8.17. ADDC: Unsigned Add with CarryEncoding (format 8, first word at lower address):

1 0 0 0 0 0 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 1 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

ADDC Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

Rd ← Ra + Rb + carry

carry ← ( ( Ra + Rb + carry) ≥ 216 ) ? 1 : 0

PC ← PC + 2

3.8.18. SUBC: Unsigned Subtract with CarryEncoding (format 8, first word at lower address):

1 0 0 0 0 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 1 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

SUBC Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

Rd ← Ra - Rb - carry

carry ← ((Rb + carry) > Ra) ? 1 : 0

PC ← PC + 2

Page 48: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

41 Copyright © 2015 Embecosm Limited

3.8.19. ANDI: Bitwise AND ImmediateEncoding (format 10, first word at lower address):

1 0 0 0 0 1 1 d2 d1 d0 a2 a1 a0 i2 i1 i0

0 0 0 i8 i7 i6 1 d5 d4 d3 a5 a4 a3 i5 i4 i3

Syntax:

ANDI Rd,Ra,I

Constraints:

a ≤ 63

d ≤ 63

I ≤ 511

Outcome:

Rd ← Ra & I

PC ← PC + 2

3.8.20. ORI: Bitwise OR immediateEncoding (format 10, first word at lower address):

1 0 0 0 1 0 0 d2 d1 d0 a2 a1 a0 i2 i1 i0

0 0 0 i8 i7 i6 1 d5 d4 d3 a5 a4 a3 i5 i4 i3

Syntax:

ORI Rd,Ra,I

Constraints:

a ≤ 63

d ≤ 63

I ≤ 511

Outcome:

Rd ← Ra | I

PC ← PC + 2

3.8.21. XORI: Bitwise Exclusive OR ImmediateEncoding (format 10, first word at lower address):

1 0 0 0 1 0 1 d2 d1 d0 a2 a1 a0 i2 i1 i0

0 0 0 i8 i7 i6 1 d5 d4 d3 a5 a4 a3 i5 i4 i3

Syntax:

XORI Rd,Ra,I

Constraints:

Page 49: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

42 Copyright © 2015 Embecosm Limited

a ≤ 63

d ≤ 63

I ≤ 511

Outcome:

Rd ← Ra ^ I

PC ← PC + 2

3.9. Detailed Descriptions of 32-bit Load/Store Instructions

3.9.1. LDB: Indexed Load ByteEncoding (format 13, first word at lower address):

1 0 1 0 0 0 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

0 0 0 s9 s8 s7 s6 d5 d4 d3 a5 a4 a3 s5 s4 s3

Syntax:

LDB Rd,(Ra,S)

Constraints:

d ≤ 63

-512 ≤ S ≤ 511

Outcome:

Rd ← dmem[Ra + SignExt(S)]

PC ← PC + 2

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.9.2. LDW: Indexed Load WordEncoding (format 13, first word at lower address):

1 0 1 0 1 0 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

0 0 0 s9 s8 s7 s6 d5 d4 d3 a5 a4 a3 s5 s4 s3

Syntax:

LDW Rd,(Ra,S)

Constraints:

d ≤ 63

-512 ≤ S ≤ 511

Outcome:

Rd ← dmem [Ra + SignExt(S)] | (dmem[Ra + SignExt(S) + 1] << 8)

PC ← PC + 2

Page 50: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

43 Copyright © 2015 Embecosm Limited

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.9.3. LDB: Indexed Load Byte with PostincrementEncoding (format 13, first word at lower address):

1 0 1 0 0 0 1 d2 d1 d0 a2 a1 a0 s2 s1 s0

0 0 0 s9 s8 s7 s6 d5 d4 d3 a5 a4 a3 s5 s4 s3

Syntax:

LDB Rd,(Ra+,S)

Constraints:

d ≤ 63

-512 ≤ S ≤ 511

Outcome:

Rd ← dmem[Ra + SignExt(S)]

Ra ← Ra + 1

PC ← PC + 2

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.9.4. LDW: Indexed Load Word with PostincrementEncoding (format 13, first word at lower address):

1 0 1 0 1 0 1 d2 d1 d0 a2 a1 a0 s2 s1 s0

0 0 0 s9 s8 s7 s6 d5 d4 d3 a5 a4 a3 s5 s4 s3

Syntax:

LDW Rd,(Ra+,S)

Constraints:

d ≤ 63

-512 ≤ S ≤ 511

Outcome:

Rd ← dmem [Ra + SignExt(S)] | (dmem[Ra + SignExt(S) + 1] << 8)

Ra ← Ra + 2

PC ← PC + 2

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

Page 51: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

44 Copyright © 2015 Embecosm Limited

3.9.5. LDB: Indexed Load Byte with PredecrementEncoding (format 13, first word at lower address):

1 0 1 0 0 1 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

0 0 0 s9 s8 s7 s6 d5 d4 d3 a5 a4 a3 s5 s4 s3

Syntax:

LDB Rd,(-Ra,S)

Constraints:

d ≤ 63

-512 ≤ S ≤ 511

Outcome:

Ra ← Ra - 1

Rd ← dmem[Ra + SignExt(S)]

PC ← PC + 2

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.9.6. LDW: Indexed Load Word with PredecrementEncoding (format 13, first word at lower address):

1 0 1 0 1 1 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

0 0 0 s9 s8 s7 s6 d5 d4 d3 a5 a4 a3 s5 s4 s3

Syntax:

LDW Rd,(-Ra,S)

Constraints:

d ≤ 63

-512 ≤ S ≤ 511

Outcome:

Ra ← Ra - 2

Rd ← dmem [Ra + SignExt(S)] | (dmem[Ra + SignExt(S) + 1] << 8)

PC ← PC + 2

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.9.7. STB: Indexed Store ByteEncoding (format 13, first word at lower address):

1 0 1 1 0 0 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

Page 52: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

45 Copyright © 2015 Embecosm Limited

0 0 0 s9 s8 s7 s6 d5 d4 d3 a5 a4 a3 s5 s4 s3

Syntax:

STB (Rd,S),Ra

Constraints:

d ≤ 63

-512 ≤ S ≤ 511

Outcome:

dmem[Rd + SignExt(S)] ← (Ra & 255)

PC ← PC + 2

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.9.8. STW: Indexed Store WordEncoding (format 13, first word at lower address):

0 0 1 1 1 0 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

0 0 0 s9 s8 s7 s6 d5 d4 d3 a5 a4 a3 s5 s4 s3

Syntax:

STW (Rd,S),Ra

Constraints:

d ≤ 63

-512 ≤ S ≤ 511

Outcome:

dmem[Rd + SignExt(S)] ← (Ra & 255)

dmem[Rd + SignExt(S) + 1] ← (Ra >> 8)

PC ← PC + 2

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.9.9. STB: Indexed Store Byte with PostincrementEncoding (format 13, first word at lower address):

1 0 1 1 0 0 1 d2 d1 d0 a2 a1 a0 s2 s1 s0

0 0 0 s9 s8 s7 s6 d5 d4 d3 a5 a4 a3 s5 s4 s3

Syntax:

STB (Rd+,S),Ra

Constraints:

Page 53: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

46 Copyright © 2015 Embecosm Limited

d ≤ 63

-512 ≤ S ≤ 511

Outcome:

dmem[Rd + SignExt(S)] ← (Ra & 255)

Ra ← Ra + 1

PC ← PC + 2

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.9.10. STW: Indexed Store Word with PostincrementEncoding (format 13, first word at lower address):

1 0 1 1 1 0 1 d2 d1 d0 a2 a1 a0 s2 s1 s0

0 0 0 s9 s8 s7 s6 d5 d4 d3 a5 a4 a3 s5 s4 s3

Syntax:

STW (Rd+,S),Ra

Constraints:

d ≤ 63

-512 ≤ S ≤ 511

Outcome:

dmem[Rd + SignExt(S)] ← (Ra & 255)

dmem[Rd + SignExt(S) + 1] ← (Ra >> 8)

Ra ← Ra + 2

PC ← PC + 2

Notes:

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.9.11. STB: Indexed Store Byte with PredecrementEncoding (format 13, first word at lower address):

1 0 1 1 0 1 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

0 0 0 s9 s8 s7 s6 d5 d4 d3 a5 a4 a3 s5 s4 s3

Syntax:

STB (-Rd,S),Ra

Constraints:

d ≤ 63

-512 ≤ S ≤ 511

Page 54: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

47 Copyright © 2015 Embecosm Limited

Outcome:

Ra ← Ra - 1

dmem[Rd + SignExt(S)] ← (Ra & 255)

PC ← PC + 2

Notes:

For the avoidance of doubt, the decrement of Ra is carried out before Ra is used tocompute the address for loading.

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.9.12. STW: Indexed Store Word with PredecrementEncoding (format 13, first word at lower address):

1 0 1 1 1 1 0 d2 d1 d0 a2 a1 a0 s2 s1 s0

0 0 0 s9 s8 s7 s6 d5 d4 d3 a5 a4 a3 s5 s4 s3

Syntax:

STW (-Rd,S),Ra

Constraints:

d ≤ 63

-512 ≤ S ≤ 511

Outcome:

Ra ← Ra - 2

dmem[Rd + SignExt(S)] ← (Ra & 255)

dmem[Rd + SignExt(S) + 1] ← (Ra >> 8)

PC ← PC + 2

Notes:

For the avoidance of doubt, the decrement of Ra is carried out before Ra is used tocompute the address for loading.

This opcode accesses data memory, and the computed address is therefore a byteaddress. Accessing a non-existent memory location will trigger a bus error exception.

3.10. Detailed Descriptions of 32-bit Branch/Jump InstructionsNoteAs with the 16-bit instructions, only a limited range of comparisons is provided.See Section 3.6 for an explanation.

3.10.1. BRA: Relative BranchEncoding (format 17, first word at lower address):

1 1 0 0 0 0 0 s8 s7 s6 s5 s4 s3 s2 s1 s0

0 0 0 s21 s20 s19 s18 s17 s16 s15 s14 s13 s12 s11 s10 s9

Page 55: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

48 Copyright © 2015 Embecosm Limited

Syntax:

BRA S

Constraints:

-2,097,152 ≤ S ≤ 2,097,151

Outcome:

PC ← PC + SignExt(S)

Notes:

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.10.2. BAL: Relative Branch and LinkEncoding (format 16, first word at lower address):

1 1 0 0 0 0 1 s5 s4 s3 s2 s1 s0 b2 b1 b0

0 0 0 s18 s17 s16 s15 s14 s13 s12 s11 s10 s9 b5 b4 b3

Syntax:

BAL S,Rb

Constraints:

b ≤ 63

-262,144 ≤ S ≤ 262,141

Outcome:

Rb ← PC + 2

PC ← PC + SignExt(S)

Notes:

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.10.3. BEQ: Relative Branch if EqualEncoding (format 12, first word at lower address):

1 1 0 0 0 1 0 s2 s1 s0 a2 a1 a0 b2 b1 b0

0 0 0 s9 s8 s7 s6 s5 s4 s3 a5 a4 a3 b5 b4 b3

Syntax:

BEQ S,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

Page 56: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

49 Copyright © 2015 Embecosm Limited

-512 ≤ S ≤ 511

Outcome:

PC ← (Ra = Rb) ? PC + SignExt(S) : PC + 2

Notes:

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.10.4. BNE: Relative Branch if Not EqualEncoding (format 12, first word at lower address):

1 1 0 0 0 1 1 s2 s1 s0 a2 a1 a0 b2 b1 b0

0 0 0 s9 s8 s7 s6 s5 s4 s3 a5 a4 a3 b5 b4 b3

Syntax:

BNE S,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

-512 ≤ S ≤ 511

Outcome:

PC ← (Ra ≠ Rb) ? PC + SignExt(S) : PC + 2

Notes:

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.10.5. BLTS: Relative Branch if Signed Less ThanEncoding (format 12, first word at lower address):

1 1 0 0 1 0 0 s2 s1 s0 a2 a1 a0 b2 b1 b0

0 0 0 s9 s8 s7 s6 s5 s4 s3 a5 a4 a3 b5 b4 b3

Syntax:

BLTS S,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

-512 ≤ S ≤ 511

Outcome:

PC ← (Ra < Rb) ? PC + SignExt(S) : PC + 2

Page 57: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

50 Copyright © 2015 Embecosm Limited

Notes:

The comparison between Ra and Rb is a signed comparison, where the contents of eachregister is treated as a 2's-complement signed number.

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.10.6. BGTS: Relative Branch if Signed Greater ThanEncoding (format 12, first word at lower address):

1 1 0 0 1 0 1 s2 s1 s0 a2 a1 a0 b2 b1 b0

0 0 0 s9 s8 s7 s6 s5 s4 s3 a5 a4 a3 b5 b4 b3

Syntax:

BGTS S,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

-512 ≤ S ≤ 511

Outcome:

PC ← (Ra > Rb) ? PC + SignExt(S) : PC + 2

Notes:

The comparison between Ra and Rb is a signed comparison, where the contents of eachregister is treated as a 2's-complement signed number.

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.10.7. BLTU: Relative Branch if Unsigned Less ThanEncoding (format 12, first word at lower address):

1 1 0 0 1 1 0 s2 s1 s0 a2 a1 a0 b2 b1 b0

0 0 0 s9 s8 s7 s6 s5 s4 s3 a5 a4 a3 b5 b4 b3

Syntax:

BLTU S,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

-512 ≤ S ≤ 511

Outcome:

PC ← (Ra < Rb) ? PC + SignExt(S) : PC + 2

Page 58: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

51 Copyright © 2015 Embecosm Limited

Notes:

The comparison between Ra and Rb is an unsigned comparison.

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.10.8. BGTU: Relative Branch if Unsigned Greater ThanEncoding (format 12, first word at lower address):

1 1 0 0 1 1 1 s2 s1 s0 a2 a1 a0 b2 b1 b0

0 0 0 s9 s8 s7 s6 s5 s4 s3 a5 a4 a3 b5 b4 b3

Syntax:

BGTU S,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

-512 ≤ S ≤ 511

Outcome:

PC ← (Ra > Rb) ? PC + SignExt(S) : PC + 2

Notes:

The comparison between Ra and Rb is an unsigned comparison.

Remember that the program counter is a word address, so the offset is the number ofwords by which to adjust the PC.

Branching to a non-existent location will trigger a bus error exception.

3.10.9. JMP: Absolute JumpEncoding (format 8, first word at lower address):

1 1 0 1 0 0 0 d2 d1 d0 0 0 0 0 0 0

0 0 0 1 0 0 0 d5 d4 d3 0 0 0 0 0 0

Syntax:

JMP Rd

Constraints:

d ≤ 63

Outcome:

PC ← Rd

Notes:

Remember that the program counter is a word address, so the value in Rd should bea word address.

Page 59: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

52 Copyright © 2015 Embecosm Limited

Jumping to a non-existent location will trigger a bus error exception.

3.10.10. JAL: Absolute Jump and LinkEncoding (format 8, first word at lower address):

1 1 0 1 0 0 1 d2 d1 d0 0 0 0 b2 b1 b0

0 0 0 0 0 0 0 d5 d4 d3 0 0 0 b5 b4 b3

Syntax:

JAL Rd,Rb

Constraints:

b ≤ 63

d ≤ 63

Outcome:

Rb ← PC + 2

PC ← Rd

Notes:

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jumping to a non-existent location will trigger a bus error exception.

3.10.11. JEQ: Absolute Jump if EqualEncoding (format 8, first word at lower address):

1 1 0 1 0 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

JEQ Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

PC ← (Ra = Rb) ? Rd : PC + 2

Notes:

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.10.12. JNE: Absolute Jump if Not EqualEncoding (format 8, first word at lower address):

Page 60: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

53 Copyright © 2015 Embecosm Limited

1 1 0 1 0 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

JNE Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

PC ← (Ra ≠ Rb) ? Rd : PC + 2

Notes:

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.10.13. JLTS: Absolute Jump if Signed Less ThanEncoding (format 8, first word at lower address):

1 1 0 1 1 0 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

JLTS Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

PC ← (Ra < Rb) ? Rd : PC + 2

Notes:

The comparison between Ra and Rb is a signed comparison, where the contents of eachregister is treated as a 2's-complement signed number.

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.10.14. JGTS: Absolute Jump if Signed Greater ThanEncoding (format 8, first word at lower address):

1 1 0 1 1 0 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

Page 61: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

54 Copyright © 2015 Embecosm Limited

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

JGTS Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

PC ← (Ra > Rb) ? Rd : PC + 2

Notes:

The comparison between Ra and Rb is a signed comparison, where the contents of eachregister is treated as a 2's-complement signed number.

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.10.15. JLTU: Absolute Jump if Unsigned Less ThanEncoding (format 8, first word at lower address):

1 1 0 1 1 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

JLTU Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

PC ← (Ra < Rb) ? Rd : PC + 2

Notes:

The comparison between Ra and Rb is an unsigned comparison.

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.10.16. JGTU: Absolute Jump if Unsigned Greater ThanEncoding (format 8, first word at lower address):

1 1 0 1 1 1 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

Page 62: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

55 Copyright © 2015 Embecosm Limited

0 0 0 0 0 0 0 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

JGTU Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 63

Outcome:

PC ← (Ra > Rb) ? Rd : PC + 2

Notes:

The comparison between Ra and Rb is an unsigned comparison.

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.10.17. JMPL: Absolute Jump LongEncoding (format 8, first word at lower address):

1 1 0 1 0 0 0 d2 d1 d0 0 0 0 0 0 0

0 0 0 0 0 0 1 d5 d4 d3 0 0 0 0 0 0

Syntax:

JMPL Rd

Constraints:

d ≤ 62

(d % 2) = 2

Outcome:

PC ← (Rd+1 << 16) | Rd

Notes:

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jumping to a non-existent location will trigger a bus error exception.

3.10.18. JALL: Absolute Jump Long and LinkEncoding (format 8, first word at lower address):

1 1 0 1 0 0 1 d2 d1 d0 0 0 0 b2 b1 b0

0 0 0 0 0 0 1 d5 d4 d3 0 0 0 b5 b4 b3

Syntax:

Page 63: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

56 Copyright © 2015 Embecosm Limited

JALL Rd,Rb

Constraints:

b ≤ 63

d ≤ 62

(d % 2) = 2

Outcome:

Rb ← PC + 2

PC ← (Rd+1 << 16) | Rd

Notes:

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jumping to a non-existent location will trigger a bus error exception.

3.10.19. JEQL: Absolute Jump Long if EqualEncoding (format 8, first word at lower address):

1 1 0 1 0 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 1 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

JEQL Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 62

(d % 2) = 2

Outcome:

PC ← (Ra = Rb) ? ((Rd+1 << 16) | Rd) : PC + 2

Notes:

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.10.20. JNEL: Absolute Jump Long if Not EqualEncoding (format 8, first word at lower address):

1 1 0 1 0 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 1 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

JNEL Rd,Ra,Rb

Page 64: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

57 Copyright © 2015 Embecosm Limited

Constraints:

a ≤ 63

b ≤ 63

d ≤ 62

(d % 2) = 2

Outcome:

PC ← (Ra ≠ Rb) ? ((Rd+1 << 16) | Rd) : PC + 2

Notes:

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.10.21. JLTSL: Absolute Jump Long if Signed Less ThanEncoding (format 8, first word at lower address):

1 1 0 1 1 0 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 1 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

JLTSL Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 62

(d % 2) = 2

Outcome:

PC ← (Ra < Rb) ? ((Rd+1 << 16) | Rd) : PC + 2

Notes:

The comparison between Ra and Rb is a signed comparison, where the contents of eachregister is treated as a 2's-complement signed number.

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.10.22. JGTSL: Absolute Jump Long if Signed Greater ThanEncoding (format 8, first word at lower address):

1 1 0 1 1 0 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 1 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

Page 65: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

58 Copyright © 2015 Embecosm Limited

JGTSL Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 62

(d % 2) = 2

Outcome:

PC ← (Ra > Rb) ? ((Rd+1 << 16) | Rd) : PC + 2

Notes:

The comparison between Ra and Rb is a signed comparison, where the contents of eachregister is treated as a 2's-complement signed number.

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.10.23. JLTUL: Absolute Jump Long if Unsigned Less ThanEncoding (format 8, first word at lower address):

1 1 0 1 1 1 0 d2 d1 d0 a2 a1 a0 b2 b1 b0

0 0 0 0 0 0 1 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

JLTUL Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 62

(d % 2) = 2

Outcome:

PC ← (Ra < Rb) ? ((Rd+1 << 16) | Rd) : PC + 2

Notes:

The comparison between Ra and Rb is an unsigned comparison.

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.10.24. JGTUL: Absolute Jump Long if Unsigned Greater ThanEncoding (format 8, first word at lower address):

1 1 0 1 1 1 1 d2 d1 d0 a2 a1 a0 b2 b1 b0

Page 66: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

59 Copyright © 2015 Embecosm Limited

0 0 0 0 0 0 1 d5 d4 d3 a5 a4 a3 b5 b4 b3

Syntax:

JGTUL Rd,Ra,Rb

Constraints:

a ≤ 63

b ≤ 63

d ≤ 62

(d % 2) = 2

Outcome:

PC ← (Ra > Rb) ? ((Rd+1 << 16) | Rd) : PC + 2

Notes:

The comparison between Ra and Rb is an unsigned comparison.

Remember that the program counter is a word address, so the value in Rd should bea word address.

Jump to a non-existent location will trigger a bus error exception.

3.11. Detailed Descriptions of 32-bit Miscellaneous InstructionsThere are currently no 32-bit instructions defined in this class.

Page 67: AAP: An Altruistic Processor Bitwise AND Immediate ..... 41 3.8.20. ORI: Bitwise OR immediate ..... 41 3.8.21. XORI: Bitwise Exclusive OR Immediate ..... 41

60 Copyright © 2015 Embecosm Limited

Chapter 4. ABI4.1. Defined RegistersBecause of the variability in the architecture it is difficult to be too rigid on the ABI. In anycase part of the purpose of this architecture to allow exploration of different ABI's. Within thissection, the identifier Rmax is used to indicate the highest numbered register in the architecture.

The meanings of the following registers are defined.

• R0: Link Register

• R1: Stack Pointer

Note in particular no frame pointer is defined. It is up to the implementer to decide policy withregard to use of a frame pointer.

4.2. Calling ConventionAgain this is flexible, particularly where there can be very few registers. These are the generalguidelines.

• All byte arguments are promoted to 16-bits.

• Arguments are passed in R2–R7 (or R2–Rmax if there are fewer than 8 registers).

• Results are returned on the same registers used to pass arguments.

• Varargs are always passed on the stack.

• A good guideline is that approximately one third of unallocated registers should be callersaved, although that can increase to one half where there are plenty of registers. Thefollowing registers (if present) are caller saved: R10, R13, R16, R19, R22, R25, R28, R31, R33,R35, R37, R39, R41, R43, R45, R47, R49, R51, R53, R55, R57, R59, R61 and R63.