Wednesday, February 8, 2017

Learning Assembly ARM: S:020617 - Current

Refferences:
nop- do nothing
pop / push:
push {r3} means str (store) r3, [sp, #-4]!
store r3 into [__] and decrement sp by 4
pop {r3} means ldr r3, [sp], #4
load r3 from sd and increment sp by 4
Registers:
16 generic 32-bit register
R13: stack pointer-keep track of memory address
R14: link register-automatically return value
R15: program counter
R0 to R7 (low registers);R8-R12 high registers
R13 is SP register
g (the NOP (No Operation)
instruction has no effect beyond using one machine cycle to run itself
add: add
sub: subtract
ldr vs str in ARM:
STR instructions store a word to memory.
LDR instructions load a word from memory.
bx:
EORS: exclusive or
use ";" to comment in ARM
Q&A
1) What is # in ARM?
for example LDR R3, [R0,#4] 
that means that it will load R0 with 4 additional bytes to R3 but Why?
To extend the memory

2) How to do multiplication in assembly?
- we have to convert it to binary and do addition vs subtraction because assembly does not have multiplication operation
- let do 1111 x 10 (2) = 11110, seeing that 1111 is shifted to the left 1 unit.
- Assembly has "logical shift left"; therefore we can use it for multiplication with 2^x
- lsl rd,rm,#_ (in which _ is positions you want to shift)

3) How to compare in assembly?
Syntax
CMP{cond} Rn, Operand2
CMN{cond} Rn, Operand2
CMP will take Rn - Rm, from left to right
Compare 2 values and return 1 if the first value is greater than the second and otherwise.

cmp --- to compare 2 value
bgt --- branch greater than to a label
That's the hint, I guess you can finish the rest

4) How to clear register?
Instead of clearing you can use move (mov) to attach the address to register. 

5)How to make loop in Assembly?


int i;i=0;
do {
//what ya wanna do
i++;
}  while (i<10);
6) What is 0x in C?
It's the prefix for hexadecimal value

7) Bit arithmetic
http://stackoverflow.com/questions/11815894/how-to-read-write-arbitrary-bits-in-c-c

8)

ADD R0,#2, the register R0 is both the source and destination and this instruction means R0←R0+2
The LDR Rd,=const pseudo-instruction can construct any 32-bit numeric constant in a single instruction.