In: Computer Science
Evaluate the following ARM code line by line and show the state of each register and PC after execution.
Initial state: X1 = 0, X2 = 0, X3 = 0, X4 = 0x7, X5 = 0
If there are multiple values for a given register at a particular instruction list them in order
| 
 X1  | 
 X2  | 
 X3  | 
 X4  | 
 X5  | 
 PC after execution  | 
||
| 
 0x100  | 
 ADDI X1,X1,#4096  | 
||||||
| 
 0x104  | 
 B #8  | 
||||||
| 
 0x108  | 
 ADDI X3,X3,#1  | 
||||||
| 
 0x10C  | 
 CBNZ X3, #2  | 
||||||
| 
 0x110  | 
 CBZ X2, #2  | 
||||||
| 
 0x114  | 
 B #-1  | 
||||||
| 
 0x118  | 
 AND X5,X3,X4  | 
||||||
| 
 0x11C  | 
 XOR X5,X3,X4  | 
||||||
| 
 0x120  | 
 ORR X2,X3,X4  | 
||||||
| 
 0x124  | 
 CBZ X2, #7  | 
||||||
| 
 0x128  | 
 BREAK  | 
Below are the details of all the instructions:
Note: The instructions do not seem to form an actual practical program and hence, they are merely judging the understanding of these instructions.
In snapshot:

In text:
| X1 | X2 | X3 | X4 | X5 | PC after execution | ||
| 0x100 | ADDI X1,X1,#4096 | 0, 0x1000 | 0 | 0 | 0x7 | 0 | 0x104 | 
| Equivalent to X1=X1+1000 (4096 = 0x1000). PC points at next instruction at 0x104 | |||||||
| 0x104 | B #8 | 0, 0x1000 | 0 | 0 | 0x7 | 0 | 0x,108, 0x128 | 
| Equivalent to a jump instruction with an offset of 8*4. So PC jumps to 0x108 (pointing to next direction) plus 8*4 | |||||||
| 0x108 | ADDI X3,X3,#1 | 0x1000 | 0 | 0, 0x1 | 0x7 | 0 | 0x10C | 
| Equivalent to X3=X3+1. PC points at next instruction at 0x10C | |||||||
| 0x10C | CBNZ X3, #2 | 0x1000 | 0 | 0x1 | 0x7 | 0 | 0x110, 0x118 | 
| If X3 not equal to 0, then jump 2 steps ahead. PC = PC+2*4 | |||||||
| 0x110 | CBZ X2, #2 | 0x1000 | 0 | 0x1 | 0x7 | 0 | 0x114, 0x11C | 
| If X2 equal to 0, then jump 2 steps ahead. PC = PC+2*4 | |||||||
| 0x114 | B #-1 | 0x1000 | 0 | 0x1 | 0x7 | 0 | 0x118, 0x114 | 
| Equivalent to a jump instruction with an offset of -1*4. So PC jumps to 0x108 (pointing to next direction) minus 4. This might result in an infinite loop | |||||||
| 0x118 | AND X5,X3,X4 | 0x1000 | 0 | 0x1 | 0x7 | 0, 0x1 | 0x11C | 
| Equivalent to X5=X3 AND X1. This is a bitwise operation [X3 (0000 0001) AND X4 (0000 0111) = 0000 0001] . PC points at next instruction. | |||||||
| 0x11C | XOR X5,X3,X4 | 0x1000 | 0 | 0x1 | 0x7 | 0x1,0x6 | 0x120 | 
| Equivalent to X5=X3 XOR X1. This is a bitwise operation [X3 (0000 0001) XOR X4 (0000 0111) = 0000 0110] . PC points at next instruction. | |||||||
| 0x120 | ORR X2,X3,X4 | 0x1000 | 0, 0x7 | 0x1 | 0x7 | 0x6 | 0x124 | 
| Equivalent to X2=X3 XOR X4. This is a bitwise operation [X3 (0000 0001) OR X4 (0000 0111) = 0000 0111] . PC points at next instruction. | |||||||
| 0x124 | CBZ X2, #7 | 0x1000 | 0, 0x7 | 0x1 | 0x7 | 0x6 | 0x128, 0x144 | 
| If X2 equal to 0, then jump 2 steps ahead. PC = PC+7*4 | |||||||
| 0x128 | Break | 0x1000 | 0, 0x7 | 0x1 | 0x7 | 0x6 | 0x129 | 
| End program, size of instruction is 1. | |||||||