4If we don’t use the %, the assembler will return a syntax error. ARC RegistersARC has 32 general purpose registers from r0 to r32However, r0 is set to value 0 and cannot be changed.We can use all the other registers.Using registers is very easy ! Just refer to their contents using the “%” symbol.E.g., Consider the instruction: andcc %r1 %r2 %r3In English this stands for: “Compute the logical bitwise AND of the contents of register r1 and register r2 and store in register r3”If we don’t use the %, the assembler will return a syntax error.
5User-Visible Registers PC: program counter, next instruction to executeStack Pointer: we will study later.
6ARC MemoryUsing memory is not so straightforward as registers, but is still quite easy.If you enclose a memory location in “[ ]” it refers to the contents of the memoryElse it refers to the actual memory location.Consider a Java (or C/C++ statement) int x = 10;In ARC, we can allocate this memory asx: 10Now, to access the content of this memory we must enclose “x” in “[ ]”E.g., Consider the instruction:ld [x] %r1 // “Load the contents of memory location x in register r1”On the other hand, if we do not enclose x within the “[ ]”, thenWith “ld” and “st” instructions you will get a syntax error.These instructions require memory content, not data !With “call” instruction it will end up calling the actual location of the memory.E.g., call x ; // here it will call the instruction located at memory location “x”
7Summary so far … We looked at: ARC instructionsUsing registersUsing memory.Lets look at a few ARC programs on the simulator and then get our hands dirty into how the assembly code is actually represented.
8Example program Memory locations are represented within [ ] ld and st are the only two operations allowed on memory.These are information for the assembler. They are not part of the assembly language
9Instruction Format Every ARC instruction is 32 bits in length. For instance, the instruction below must fit within 32 bits when represented in binary.To do this, ARC enforces certain formats that allow us to use the 32 bits in different ways.These are called instruction formats.A format defines how the various bit fields of an instruction are laid out within 32 bits and how it is interpreted by the ARC control unit.
12ARC Pseudo-Ops• Pseudo-ops are instructions to the assembler. They are not part of the ISA.
13.org 3000 Adding 5 integers … a: 10 25 2 3 4 a_start: 3000 counter: 0 output: 0ld [a_start], %r1 ! Load the starting address of a into %r1ld [counter], %r2 ! Register r2 is the counter.andcc %r3,%r0, %r3 ! What does this do?loop: subcc %r2, 5, %r0 ! Have we reached the end of the array?be done ! If %r2 – 5 = 0, exit loop.addcc %r2, 1, %r2 ! Increment counterld %r1, %r4 ! Load the number from the arrayaddcc %r4, %r3, %r3 ! Accumulate sum into %r3.addcc %r1, 4, %r1 ! Goto next addressba loopdone: st %r3, [output]jmpl %r15+4, %r0
14Summary Storage location for address of the array a. Having this location allows us to load the address “3000” into a register.Length is being used as a “counter” to determine when to end the loop.
15Other ARC instructions Software traps:Allows programs to invoke services from the OS/hardware, e.g., reading a keyboard or writing onto a display.ARC has trap instructions – but they do not control the OS/hardware (due to JVM limitations).
16Summary Assembly programming 101 Different language, but still within same paradigm