Professional Documents
Culture Documents
Microcontroller
Santanu Chattopadhyay
Dept. of Electronics & Elec. Comm. Engg.
Indian Institute of Technology, Kharagpur
India – 721 302
Email: santanu@ece.iitkgp.ernet.in
Microcontrollers
Single-chip computers
Relatively simple CPU with timers, serial /
parallel, digital / analog input / output lines
On-chip program memory
A small on-chip read-write memory (scratch pad)
Extended memory interfacing
Targeted towards small applications
Operating frequency as low as 32KHz, though
many high speed microcontrollers available
Features sought after
Highest available speed should be sufficient for
the application
Size of the chip – 40 pin DIP, QFP (quad flat
package)
Amount of on-chip ROM/RAM
Cost of single chip
Availability of development platform
On-chip debugging
Availability in the market
Example microcontrollers
31 30 29 28 27 8 7 6 5 4 0
N Z C V Unused I F T Mode
Instructions –
STMIA/LDMIA: Increment after
STMIB/LDMIB: Increment before
STMDA/LDMDA: Decrement after
STMDB/LDMDB: Decrement before
Example –
; R12 points to start of source data
; R14 points to the end of source data
; R13 points to the start of the destination data
Loop LDMIA R12!, {R0-R11}; load 48 bytes
STMIA R13!, {R0-R11}; and store them
CMP R12, R14; check for the end
BNE Loop; and loop until done
Multiplication Instruction
Several versions
Integer multiplication (32-bit result)
Long integer multiplication (64-bit result)
Instructions
MUL – 32 bit multiply
Example
MUL R0, R1, R2; R0 = R1 * R2
MULA R0, R1, R2, R3; R0 = R1 * R2 + R3
Multiplication Instruction (Contd.)
31 28 27 25 24 23 0
Condition 1 0 1 L Offset
Link bit, 0 = branch, 1 = branch with link
Offset calculation:
•Compute 26-bit difference between branch instruction and target
•Right shift by 2-bits, as instruction are always word aligned, least
significant two bits are always zeros
•24-bit value stored with the instruction
•During execution, offset left shifted by 2 bits, sign extended to 32 bits,
added to PC to get the branch target
Swap Instruction
Atomic operation in which a memory read is followed by a memory
write
Moves byte or word between registers and memory
Format:
SWP Rd, Rm, [Rn]
16-bit
Instruction THUMB ARM
THUMB
pipeline decompressor Instruction
code
decoder
ARM decompressor
Advantages of THUMB