Difference between revisions of "Assembly Language"
(→SUB - Subtract) |
|||
(21 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | ===TRC Video=== | ||
+ | <youtube>https://www.youtube.com/watch?v=D9rxI2hVEfQ</youtube> | ||
+ | |||
+ | https://www.youtube.com/watch?v=D9rxI2hVEfQ | ||
+ | |||
+ | ==Example Programs== | ||
+ | [[Assembly Language Multiplication]] | ||
+ | |||
+ | [[Assembly Language Division]] | ||
+ | |||
+ | [[Assembly Language IF]] | ||
+ | |||
+ | [[Assembly Language IF ELSE]] | ||
+ | |||
+ | [[Assembly Language DO WHILE]] | ||
+ | |||
+ | [[Assembly Language FOR]] | ||
+ | |||
+ | [[Assembly Language WHILE]] | ||
+ | |||
+ | [[Assembly Language Check for ODD / EVEN]] | ||
+ | |||
+ | [[Assembly Language Twos Complement]] | ||
+ | |||
+ | [[Assembly Language Logical Shift]] | ||
+ | |||
==Operands== | ==Operands== | ||
The operand can be interpreted in two different ways, if it uses: | The operand can be interpreted in two different ways, if it uses: | ||
Line 4: | Line 30: | ||
*Rm uses the value stored in register m | *Rm uses the value stored in register m | ||
− | ==LDR - Load== | + | ==Op Codes== |
+ | Below is a list of the OpCodes used within your examinations. This table will always be given to you with a small explanation and syntax for each command. | ||
+ | |||
+ | ===LDR - Load=== | ||
This instruction is to load a value stored in memory into a CPU register. | This instruction is to load a value stored in memory into a CPU register. | ||
− | ==STR - Store== | + | LDR Rd, <memory ref> |
− | This instruction is to store a value from a register | + | |
+ | ===STR - Store=== | ||
+ | This instruction is to store a value from Register d into Memory location <memory ref>. | ||
+ | |||
+ | STR Rd, <memory ref> | ||
+ | |||
+ | ===ADD - Add=== | ||
+ | Operation used to add two numbers together, the value in the operand to the value in Register n. | ||
+ | |||
+ | The output is stored in Register d | ||
+ | |||
+ | ADD Rd, Rn, <operand> | ||
+ | |||
+ | ===SUB - Subtract=== | ||
+ | operation used to subtract two numbers from each other, the value in the operand from the value in Register n. | ||
+ | |||
+ | The output is stored in Register d | ||
+ | |||
+ | SUB Rd, Rn, <operand> | ||
+ | |||
+ | ===MOV - Move=== | ||
+ | This instruction is to copy a value into a register. The value from the operand is stored in Register d | ||
+ | |||
+ | MOV Rd, <operand> | ||
+ | |||
+ | ===CMP - Compare=== | ||
+ | The CMP instruction compares two operands. It is generally used in conditional execution and is needed if you wish to do a conditional branch. It compares the operand with the Register n. | ||
+ | |||
+ | CMP Rn, <operand> | ||
+ | |||
+ | ===B - Branch=== | ||
+ | This will always branch to the instruction at position <label> in the program. | ||
+ | |||
+ | B <label> | ||
+ | |||
+ | ===BEQ - Branch If Equal=== | ||
+ | This must follow a CMP, and if the CMP values are equal this OpCode will branch to the specified <label> | ||
+ | |||
+ | BEQ <label> | ||
+ | |||
+ | ===BNE - Branch If Not Equal=== | ||
+ | This must follow a CMP, and if the CMP values are not equal this OpCode will branch to the specified <label> | ||
+ | |||
+ | BNE <label> | ||
+ | |||
+ | ===BGT - Branch If Greater Than=== | ||
+ | This must follow a CMP, and if the CMP values are Greater Than this OpCode will branch to the specified <label> | ||
+ | |||
+ | BGT <label> | ||
+ | |||
+ | ===BLT - Branch If Less Than=== | ||
+ | This must follow a CMP, and if the CMP values are Less Than this OpCode will branch to the specified <label> | ||
+ | |||
+ | BLT <label> | ||
+ | |||
+ | ===AND - Bitwise And=== | ||
+ | This OpCode will perform a bitwise logical AND between the values in Register n and the <operand>. | ||
+ | |||
+ | This will compare both inputs, it will output a 1 for each bit when both inputs are a 1. All other outputs will be a 0 | ||
+ | |||
+ | The result is stored in Register d | ||
+ | |||
+ | AND Rd, Rn, <operand> | ||
+ | |||
+ | ===ORR - Bitwise Or=== | ||
+ | This OpCode will perform a bitwise logical OR between the values in Register n and the <operand>. | ||
+ | |||
+ | This will compare both inputs, it will output a 1 for each bit when either inputs are a 1. All other outputs will be a 0 | ||
+ | |||
+ | The result is stored in Register d | ||
+ | |||
+ | ORR Rd, Rn, <operand> | ||
+ | |||
+ | ===EOR - Bitwise Xor=== | ||
+ | This OpCode will perform a bitwise logical XOR between the values in Register n and the <operand>. | ||
+ | |||
+ | This will compare both inputs, it will output a 1 for each bit when either but not both inputs are a 1. All other outputs will be a 0 | ||
+ | |||
+ | The result is stored in Register d | ||
+ | |||
+ | EOR Rd, Rn, <operand> | ||
+ | |||
+ | ===MVN - Bitwise Not=== | ||
+ | This OpCode will perform a bitwise logical NOT between the value in the <operand>. | ||
+ | |||
+ | This will negate the input by swapping all 1's for 0's, and 0's for 1's | ||
+ | |||
+ | The result is stored in Register d | ||
+ | |||
+ | MVN Rd, <operand> | ||
+ | |||
+ | ===LSL - Logical Shift Left=== | ||
+ | Logically shift left the value stored in Register n by the number of bits specified by the <operand>. | ||
+ | |||
+ | The result is stored in Register d | ||
+ | |||
+ | Logical shifts can be useful as efficient ways to perform multiplication or division of unsigned integers by powers of two. Shifting left by n bits on a signed or unsigned binary number has the effect of multiplying it by 2<sub>n</sub>. | ||
+ | |||
+ | LSL Rd, Rn, <operand> | ||
+ | |||
+ | ===LSR - Logical Shift Right=== | ||
+ | Logically shift right the value stored in Register n by the number of bits specified by the <operand>. | ||
+ | |||
+ | The result is stored in Register d | ||
− | + | Logical shifts can be useful as efficient ways to perform multiplication or division of unsigned integers by powers of two. Shifting right by n bits on an unsigned binary number has the effect of dividing it by 2<sub>n</sub> (rounding towards 0). | |
− | |||
− | + | LSR Rd, Rn, <operand> | |
− | |||
− | == | + | ===HLT - Halt Program=== |
− | + | Causes the processor to stop executing your program. | |
− | + | HLT | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 08:13, 23 August 2023
Contents
- 1 TRC Video
- 2 Example Programs
- 3 Operands
- 4 Op Codes
- 4.1 LDR - Load
- 4.2 STR - Store
- 4.3 ADD - Add
- 4.4 SUB - Subtract
- 4.5 MOV - Move
- 4.6 CMP - Compare
- 4.7 B - Branch
- 4.8 BEQ - Branch If Equal
- 4.9 BNE - Branch If Not Equal
- 4.10 BGT - Branch If Greater Than
- 4.11 BLT - Branch If Less Than
- 4.12 AND - Bitwise And
- 4.13 ORR - Bitwise Or
- 4.14 EOR - Bitwise Xor
- 4.15 MVN - Bitwise Not
- 4.16 LSL - Logical Shift Left
- 4.17 LSR - Logical Shift Right
- 4.18 HLT - Halt Program
TRC Video
https://www.youtube.com/watch?v=D9rxI2hVEfQ
Example Programs
Assembly Language Multiplication
Assembly Language Check for ODD / EVEN
Assembly Language Twos Complement
Assembly Language Logical Shift
Operands
The operand can be interpreted in two different ways, if it uses:
- # it refers to a specific value to use
- Rm uses the value stored in register m
Op Codes
Below is a list of the OpCodes used within your examinations. This table will always be given to you with a small explanation and syntax for each command.
LDR - Load
This instruction is to load a value stored in memory into a CPU register.
LDR Rd, <memory ref>
STR - Store
This instruction is to store a value from Register d into Memory location <memory ref>.
STR Rd, <memory ref>
ADD - Add
Operation used to add two numbers together, the value in the operand to the value in Register n.
The output is stored in Register d
ADD Rd, Rn, <operand>
SUB - Subtract
operation used to subtract two numbers from each other, the value in the operand from the value in Register n.
The output is stored in Register d
SUB Rd, Rn, <operand>
MOV - Move
This instruction is to copy a value into a register. The value from the operand is stored in Register d
MOV Rd, <operand>
CMP - Compare
The CMP instruction compares two operands. It is generally used in conditional execution and is needed if you wish to do a conditional branch. It compares the operand with the Register n.
CMP Rn, <operand>
B - Branch
This will always branch to the instruction at position <label> in the program.
B <label>
BEQ - Branch If Equal
This must follow a CMP, and if the CMP values are equal this OpCode will branch to the specified <label>
BEQ <label>
BNE - Branch If Not Equal
This must follow a CMP, and if the CMP values are not equal this OpCode will branch to the specified <label>
BNE <label>
BGT - Branch If Greater Than
This must follow a CMP, and if the CMP values are Greater Than this OpCode will branch to the specified <label>
BGT <label>
BLT - Branch If Less Than
This must follow a CMP, and if the CMP values are Less Than this OpCode will branch to the specified <label>
BLT <label>
AND - Bitwise And
This OpCode will perform a bitwise logical AND between the values in Register n and the <operand>.
This will compare both inputs, it will output a 1 for each bit when both inputs are a 1. All other outputs will be a 0
The result is stored in Register d
AND Rd, Rn, <operand>
ORR - Bitwise Or
This OpCode will perform a bitwise logical OR between the values in Register n and the <operand>.
This will compare both inputs, it will output a 1 for each bit when either inputs are a 1. All other outputs will be a 0
The result is stored in Register d
ORR Rd, Rn, <operand>
EOR - Bitwise Xor
This OpCode will perform a bitwise logical XOR between the values in Register n and the <operand>.
This will compare both inputs, it will output a 1 for each bit when either but not both inputs are a 1. All other outputs will be a 0
The result is stored in Register d
EOR Rd, Rn, <operand>
MVN - Bitwise Not
This OpCode will perform a bitwise logical NOT between the value in the <operand>.
This will negate the input by swapping all 1's for 0's, and 0's for 1's
The result is stored in Register d
MVN Rd, <operand>
LSL - Logical Shift Left
Logically shift left the value stored in Register n by the number of bits specified by the <operand>.
The result is stored in Register d
Logical shifts can be useful as efficient ways to perform multiplication or division of unsigned integers by powers of two. Shifting left by n bits on a signed or unsigned binary number has the effect of multiplying it by 2n.
LSL Rd, Rn, <operand>
LSR - Logical Shift Right
Logically shift right the value stored in Register n by the number of bits specified by the <operand>.
The result is stored in Register d
Logical shifts can be useful as efficient ways to perform multiplication or division of unsigned integers by powers of two. Shifting right by n bits on an unsigned binary number has the effect of dividing it by 2n (rounding towards 0).
LSR Rd, Rn, <operand>
HLT - Halt Program
Causes the processor to stop executing your program.
HLT