Assembly之example

  Here is a simple example by assembly language. It is based on openMSP430. Very important is to understand "interrupt vectors". 

 1 .global main

 2 

 3 .set   P1OUT, 0x0021

 4 .set   WDTCTL, 0x0120

 5 

 6 main:

 7 

 8 /* ------------ Disable Watchdog ---------------- */

 9     MOV #0x5A80, &WDTCTL

10 

11 /* ------------ Toggle P1 ------------------------*/

12     loop:

13         MOV.B #0x00, &P1OUT

14         MOV.B #0xff, &P1OUT

15     

16     jmp loop

17     

18 

19 /* ----------------------------   INTERRUPT VECTORS  --------------- */

20 .section .vectors, "a"

21 .word loop        ; Interrupt  0 (lowest priority)    <unused>

22 .word loop        ; Interrupt  1                      <unused>

23 .word loop        ; Interrupt  2                      <unused>

24 .word loop        ; Interrupt  3                      <unused>

25 .word loop        ; Interrupt  4                      <unused>

26 .word loop        ; Interrupt  5                      <unused>

27 .word loop        ; Interrupt  6                      <unused>

28 .word loop        ; Interrupt  7                      <unused>

29 .word loop        ; Interrupt  8                      <unused>

30 .word loop        ; Interrupt  9                      <unused>

31 .word main        ; Interrupt 10                      Watchdog timer

32 .word loop        ; Interrupt 11                      <unused>

33 .word loop        ; Interrupt 12                      <unused>

34 .word loop        ; Interrupt 13                      <unused>

35 .word loop        ; Interrupt 14                      NMI

36 .word main          ; Interrupt 15 (highest priority)   RESET

 

你可能感兴趣的:(assembly)