You are on page 1of 4

50193 Microcontrollers Laboratory

' -2 2
: , ,

.1 ( ) Instruction set .MSP430


JMP ? BR

MSP430 27 24 "
) .(emulated instructions :
-Double operand .
-Single operand .
Program flow control- jump ,jump .

JMP BR BR )emulated) MOV dst,PC ,


JMP .PC new = PC old + 2 + PC offset x2

.2 MSP430.

16 16 4 ( )R0,R1,R2,R3
12 .
) : R0- Program Counter (PC "
.CPU
) :R1- Stack Pointer (SP " .
) :R2- Status Register (SR SR " CPU
.
) :R2/R3- Constant Generator Registers (CG1/CG2 ( Source
6 )As( )Register Address .
.
:R4 - R15- GeneralPurpose Registers : , ,
.

.3 :
16bit R4 . 2byte R5 . .
)copy-paste(.

BEFORE AFTER
R4 R5 R4 R5
MOV R4, R5 23Ah 1234h 23Ah 23Ah
MOV R4, R5 A1A2h FF5h A1A2h A1A2h
MOV R4, R5 97Dh random 97Dh 97Dh
MOV R4, R5 FFDh 2241h FFDh FFDh

: ,MSP430 .4

0 1 2 3 4 5 6 7 8 9 A B C D E F

: .a

BEFORE AFTER
R4 R5 R4 R5
MOV 4DE2(R5), R4 23Ah 10h 4C45h 10h
MOV 4E26(R4), R5 0Ah CDCDh 0Ah 4C20h

4DE2h+10h= 4DF2h 4E26h+0Ah= 4E30h


Move (copy) the data at the address Move (copy) the data at the address
4DF2h to register R4. 4E30h to register R5.

: .b

BEFORE AFTER
R4 R5 Memory @ R4 R4 R5
MOV @R4, R5 4E58h 4DC0h 2000h 4E58h 2000h
MOV @R4, R5 4E10h 4E90h 204Dh 4E10h 204Dh
MOV @R4+, R5 4E70h 4DA0h 4C41h 4E72h 4C41h

Move the data in the memory address that R4 is pointing on, to R5.
At the last one, after the move R4 is increment (to the next word).
: .5

BEFORE AFTER
Status Register Status Register
R13 N Z C R13 N Z C
rla.w R13 0b0001000001000000 0 0 0 0b0010000010000000 0 0 0
rlc.w R13 ABCDh 0 0 1 579Bh 0 0 1
rra.b R13 81h 0 0 0 C0h 1 0 1
rrc.w R13 1212h 1 1 1 8909h 1 0 0

N: Set if result is negative, else reset. Z: Set if result is zero, else reset.
1.rotate word or byte left arithmetically: C MSB MSB1 .... LSB+1 LSB 0
0b0001.0000.0100.0000 0b0010.0000.1000.0000 C=0
2.rotate word or byte left through carry: C MSB MSB1 .... LSB+1 LSB C
C=1 , ABCDh=0b1010.1011.1100.1101 0b0101.0111.1001.1011(=579Bh) C=0
3. rotate byte right arithmetically: MSB MSB, MSB MSB1, ... LSB+1 LSB, LSB C
81h= 0b1000.0001 0b1100.0000 (C0h), C=1
: .6
4.rotate word right through carry: C MSB MSB1 .... LSB+1 LSB C
C=1, 1212h=0b0001.0010.0001.00100b1000.1001.0000.1001 (8909h), C=0
: C .6

void main (void)


{
int a=1, b=10; // a=1 b=10,
if (a) // a=1 b=10, if a!=0 (true)
b--; // a=1 b=9, dec b (b=b-1)
else
b++; // a=1 b=9, if a==0 inc b (b=b+1)

a&=b; // a=1 b=9, a=a(AND)b= 1


b|=++a; // a=2 b=11, inc a then b=b(OR)a=11

if (a&&b) // a=2 b=11,if a!=0 and b!=0 (true) , else


{
a+=5; // a=7 b=11, a=a+5=7
b+=10; // a=7 b=21,b=b+10=21
}

a^=b; // a=18 b=11, a=a(XOR)b= 18


b&=~a; // a=18 b=9, b=b(AND)not(a)=11(and)-19=9
while(1); // a=18 b=9, endless loop (1==1 true)

}
.assembler - .7

MOV 1h,R3
MOV Ah,R4
CMP R3,0h
JZ BSUB
JNZ BINC
NEXT AND R4,R3
MOV R3,R2
INC R2
BIS R2,R4
CMP 0h,R3
JZ NEXT2
CMP 0h,R4
JZ NEXT2
ADD 5h,R3
ADD Ah,R4

NEXT2 XOR R4,R3


BIC R3,R4
LOOP JMP LOOP

BSUB DEC R3
JMP NEXT
BINC INC R3
JMP NEXT

You might also like