Reference
Load into a register from main memory
Syntax
LDR Rdest, memory
Example
LDR R0, 100
Loads the value at 100 into register 0
Pseudocode
regs[dest] ← main_mem[memory]
Name
LoaD Register
Store a registers value in main memory
Syntax
STR Rsource, memory
Example
STR R0, 100
Store the value of register 0 into memory position 100
Pseudocode
main_mem[memory] ← regs[source]
Name
SToRe
Move a register value or a number into a register
Syntax
MOV Rdest, Rsource
MOV Rdest, #number
Example
MOV R0, #10
Put the value 10 in register 0
MOV R0, R1
Put the value of register 1 in register 0
Pseudocode
When given a register
regs[dest] ← regs[source]
When given a number
regs[dest] ← number
Name
MOVe
Number constants are unsigned numbes stored using the same rules as ARM assembly, which the ALI is based on
ARM says the following about number constants:
You specify an Operand2 constant in the form:
#constant
where constant is an expression evaluating to a numeric value.
In ARM instructions, constant can have any value that can be produced by rotating an 8-bit value right by any even number of bits within a 32-bit word.
Okay to in englisg
Add a register or number to a register storing the result
Syntax
ADD Rdest, Rsource, Rother
ADD Rdest, Rsource, #number
Example
ADD R0, R1, R2
Add the value of register 2 to that of register 1 storing the result in register 0
ADD R0, R1, #100
Add 100 to the value of register 1 storing the result in register 0
Pseudocode
When given a register
regs[dest] ← regs[source] + regs[other]
When given a number
regs[dest] ← regs[source] + number
Name
ADD
Subtract a register or number from a register storing the result
Syntax
SUB Rdest, Rsource, Rother
SUB Rdest, Rsource, #number
Example
SUB R0, R1, R2
Subtract the value of register 2 from that of register 1 storing the result in register 0
ADD R0, R1, #100
Subtract 100 from the value of register 1 storing the result in register 0
Pseudocode
When given a register
regs[dest] ← regs[source] - regs[other]
When given a number
regs[dest] ← regs[source] - number
Name
SUBtract
Compare a register to another register or number, only useful when followed by a conditional branch
Syntax
CMP Rval, Rother
CMP Rval, #number
Example
CMP R0, R1
Compare the values of register 0 & register 1
ADD R0, #100
Compare register 0s value to 100
Pseudocode
When given a register
IF regs[val] = regs[other] THEN
flag ← "equal"
ELSE IF regs[val] < regs[other] THEN
flag ← "less"
ELSE
flag ← "greater"
END IF
When given a number
IF regs[val] = number THEN
flag ← "equal"
ELSE IF regs[val] < number THEN
flag ← "less"
ELSE
flag ← "greater"
END IF
Name
CoMPare
Branching is an important low level construct but is rarely seen in higher level languages
Those that do include branching generally refer to it as 'GOTOs', as is the case in BASIC, C/C++ & C#
Most languages omit branching because they build more powerful concepts atop it such as subroutines, if statements and loops
Unconditional branch or 'jump'
Syntax
B label
Example
B marker
Moves execution to the line labled 'marker'
Pseudocode
The closest construct is a subroutine call
marker()
But that would imply execution returns it's original position, this is not the case.
Name
Branch
Branch if the last CMP was equal
Syntax
BEQ label
Example
BEQ marker
Conditionally moves execution to the line labelled 'marker'
Pseudocode
IF flag = "equal" THEN
marker()
END IF
Unfortunately this doesn't exactly represent BEQ
Name
Branch EQual
Branch if the last CMP was not equal
Syntax
BNE label
Example
BNE marker
Conditionally moves execution to the line labelled 'marker'
Pseudocode
IF NOT flag = "equal" THEN
marker()
END IF
Unfortunately this doesn't exactly represent BNE
Name
Branch Not Equal
Branch if the last CMP result was greater
Syntax
BGT label
Example
BGT marker
Conditionally moves execution to the line labelled 'marker'
Pseudocode
IF flag = "greater" THEN
marker()
END IF
Unfortunately this doesn't exactly represent BGT
Name
Branch Greater Than
Branch if the last CMP result was less
Syntax
BLT label
Example
BLT marker
Conditionally moves execution to the line labelled 'marker'
Pseudocode
IF flag = "less" THEN
marker()
END IF
Unfortunately this doesn't exactly represent BLT
Name
Branch Less Than
Bitwise operations consider the binary representation of integers
It's important not to confuse these with their boolean equivalents as they can behave quite differently
Even in languages with a boolean type they are really integers where 0 is false and any other value is true, thus 'a AND b' checks that neither a or b equal 0
However bitwise operators work on the bits that make up the integer rather than it's value, for example a logical AND between 1 & 8 would be true as neither are zero but a bitwise AND between them is 0
Shifts move bits around, so shifting 0010 (2) to the left by two is 1000 (8) whereas shifting to right would be 0000 (0)
It's important to remember that even though bitwise and shift operations work with integers they do not work on them as numbers
Bitwise AND between two values
That is to say it performs a logical AND between each bit, so the AND of 2 (0010) & 6 (0110) is 2 (0010)
Syntax
AND Rdest, Rsource, Rother
AND Rdest, Rsource, #number
Example
AND R0, R1, R2
Performs a logical AND between register 1 and register 2 placing the result in register 0
Pseudocode
The AND operator is not bitwise because it produces a boolean not integer result
When given a register
regs[dest] ← regs[source] AND regs[other]
When given a number
regs[dest] ← regs[source] AND number
Name
AND
Bitwise OR between two values
That is to say it performs a logical OR between each bit, so the OR of 2 (0010) & 6 (0110) is 6 (0110)
Syntax
ORR Rdest, Rsource, Rother
ORR Rdest, Rsource, #number
Example
ORR R0, R1, R2
Performs a logical OR between register 1 and register 2 placing the result in register 0
Pseudocode
The OR operator is not bitwise because it produces a boolean not integer result
When given a register
regs[dest] ← regs[source] OR regs[other]
When given a number
regs[dest] ← regs[source] OR number
Name
OR(R)
Additional R is used to maintain consistent three letter commands
Bitwise exclusive OR between two values
That is to say it performs a logical exclusive OR between each bit, so the EOR of 2 (0010) & 6 (0110) is 4 (0100)
As exclusive OR only allows one input to be true in the style of (a or b) and not (a and b)
Syntax
EOR Rdest, Rsource, Rother
EOR Rdest, Rsource, #number
Example
EOR R0, R1, R2
Performs a logical exclusive OR (XOR) between register 1 and register 2 placing the result in register 0
Pseudocode
Neither OR or AND operators are bitwise because they are logical so produce a boolean result rather than integer
When given a register
regs[dest] ← (regs[source] OR regs[other]) AND NOT (regs[source] AND regs[other])
When given a number
regs[dest] ← (regs[source] OR number) AND NOT (regs[source] AND number)
Name
Exclusive OR
Move a register value or a number into a register having inverted it
Syntax
MVN Rdest, Rsource
MVN Rdest, #number
Example
MVN R0, #10
Put the value 10 (1010) in register 0 having inverted it to 5 (0101)
MVN R0, R1
Put the value of register 1 in register 0 having inverted it
Pseudocode
When given a register
regs[dest] ← NOT regs[source]
When given a number
regs[dest] ← NOT number
NOT is generally logical not bitwise so this sample will not show the same result as MVN
Name
MoVe NOT
Perform a left shift
Moves the binary representation a specified number of bits to the left, padding with 0s on the right
Any bits overflowing the far left are discarded
Syntax
LSL Rdest, Rsource, Rby
LSL Rdest, Rsource, #by
Example
LSL R1, R0, #1
Shift register 0 by 1 place to the left placing the result in register 1
LSL R2, R1, R0
Shift register 1 to the left by register 0s value placing the result in register 2
Pseudocode
Shifts are not generally used pseudocode but assuming it was it's use would be similar to any other operator
When given a register
regs[dest] ← regs[source] LSL regs[by]
When given a number
regs[dest] ← regs[source] LSL by
Name
Logical Shift Left
Perform a right shift
Moves the binary representation a specified number of bits to the right, padding with 0s on the left
Any bits overflowing the far right are discarded
Syntax
LSR Rdest, Rsource, Rby
LSR Rdest, Rsource, #by
Example
LSR R1, R0, #1
Shift register 0 by 1 place to the right placing the result in register 1
LSR R2, R1, R0
Shift register 1 to the right by register 0s value placing the result in register 2
Pseudocode
Shifts are not generally used pseudocode but assuming it was it's use would be similar to any other operator
When given a register
regs[dest] ← regs[source] LSR regs[by]
When given a number
regs[dest] ← regs[source] LSR by
Name
Logical Shift Right
End execution
Syntax
HALT
Example
HALT
Stops all execution
Pseudocode
The closest construct is returning from a procedure
RETURN
But that would imply execution returns to some other place rather than stopping altogether
Name
HALT