(I.e.: you can add more values that consist of more than 32 bits; but you need to use special instructions that add the carry bit)
I will not discuss these special instructions and only discuss the 32 bit instructions
|
You can use any register both as a source registers and as a destination register
You can even use the same register as source operand and as destination operand
add destReg, srcReg, op2 // destReg = srcReg + op2 sub destReg, srcReg, op2 // destReg = srcReg - op2 rsb destReg, srcReg, op2 // destReg = op2 - srcReg (reverse subtract) mul destReg, srcReg1, srcReg2 // destReg = srcReg1 * srcReg2 // Important restriction: destReg != srcReg1 !!! op2 can be: a register or a small constant (between -100 and 100) |
Examples:
Assembler instruction Effect of the assembler instruction ------------------------ -------------------------------------- add r0, r1, r2 r0 = r1 + r2 add r0, r0, r0 r0 = r0 + r0 = 2×r0 add r0, r0, #1 r0 = r0 + 1 sub r0, r1, r2 r0 = r1 - r2 rsb r0, r1, r2 r0 = r2 - r1 rsb r0, r0, #0 r0 = 0 - r1 = -r0 (negation !!) mul r0, r1, r2 r0 = r1 * r2 mul r1, r0, r0 r1 = r0 * r0 = r02 |
Comment: the rsb instruction is often used to negate the value in a register
Therefore:
For easy of programming, the ARM assembler has the following pseudo instruction to negate a register: neg rn, rm ≡ rsb rn, rm, #0 |
For example, through repeated subtraction:
Algorithm to compute Q = A/B and R = A%B Q = 0; R = A; // Subtract B from R as long as B has more to give.... while ( R ≥ B ) { Q = Q + 1; R = R - B; } |
The division function is called __aeabi_idiv.
Here is a little code to show you that you can use division in ARM assembler, but just a bit tedious:
// File: /home/cs255001/demo/asm/2-mov/divide.s // This is how you compute 14 / 3 mov r0, 14 mov r1, 3 bl __aeabi_idiv // Register r0 will contains the quotient or 14/3 = 4 |
How to run the program:
|
Comment:
|