Assembler Syntax. ○ Each assembly line begins with either a label, a blank (tab), an asterisk, or a semicolon. ○ Each line has four fields:.
53 pages
23 KB – 53 Pages
PAGE – 2 ============
Moving Up Levels of Abstraction Problems Algorithms Language Machine (ISA) Architecture Microarchitecture Circuits Devices Transistors Logic gates, multiplexers, memory, etc. MSP430 Architecture Machine code Assembly code Adapted from notes from BYU ECE124 2
PAGE – 3 ============
High Level vs. Assembly !!High Level Languages Ð!More programmer friendly Ð!More ISA independent Ð!Each high-level statement translates to several instructions in the ISA of the computer !!Assembly Languages Ð!Lower level, closer to ISA Ð!Very ISA-dependent Ð!Each instruction specifies a single ISA instruction Ð!Makes low level programming more user friendly Ð!More efficient code Adapted from notes from BYU ECE124 3
PAGE – 4 ============
Assembler Syntax !!Each assembly line begins with either a label, a blank (tab), an asterisk, or a semicolon !!Each line has four fields: {label[:]} mnemonic {operand list} {;comment} !!Some line examples are: .sect “.sysmem” ; data space var1 .word 2 ; variable var1 declaration .text ; program space loop: mov #COUNT,r5 ; get counter .end ; end of program Adapted from notes from BYU ECE124 4
PAGE – 5 ============
Symbols / Labels !!Symbols Ð!Symbols are used as labels, constants, and substitution values Ð!Symbols are stored in a symbol table Ð!A symbol name !!is a string of up to 200 alphanumeric characters (A-Z, a-z, 0-9, $, and _) !!cannot contain embedded blanks !!first character cannot be a number !!case sensitive Ð!Symbols used as labels become symbolic addresses that are associated with locations in the program !!Label Field Ð!Labels are symbols Ð!Labels must begin in column 1. Ð!A label can optionally be followed by a colon Ð!The value of a label is the current value of the Location Counter (address within program) Ð!A label on a line by itself is a valid statement Ð!Labels used locally within a file must be unique. Adapted from notes from BYU ECE124 5
PAGE – 6 ============
Mnemonics / Operands !!Mnemonic Field Ð!The mnemonic field follows the label field. Ð!The mnemonic field cannot start in column 1; if it does, it is interpreted as a label. Ð!The mnemonic field contains one of the following items: !!MSP430 instruction mnemonic ( ie. ADD, MOV, JMP) !!Assembler directive ( ie. .data, .list, . equ) !!Macro directive ( ie. .macro, . var , .mexit ) !!Macro call !!Operand Field Ð!The operand field follows the mnemonic field and contains one or more operands. Ð!The operand field is not required for all instructions or directives. Ð!An operand may consist of: !!Symbols !!Constants !!Expressions (combination of constants and symbols) Ð!Operands are separated with commas Adapted from notes from BYU ECE124 6
PAGE – 8 ============
Assembly Code Example ;******************************************************************************* ; CS/ECEn 124 Lab 4 – morse.asm: Student Code ;******************************************************************************* .cdecls C,LIST, “msp430x22x4.hAþ ; include C header COUNT .equ 2000 ;—————————————————————————— .data ; data .bss cnt,2 ; ISR counter ;—————————————————————————— .text ; Program reset RESET: mov.w #0x0280,SP ; Initialize stack pointer mov.w #WDT_MDLY_0_5,&WDTCTL ; Set Watchdog interval to ~0.5ms mov.b #WDTIE,&IE1 ; Enable WDT interrupt bis.b #0x01,&P1DIR ; P1.0 output bis.b #0x20,&P4DIR ; P4.0 output mov.w #COUNT,&cnt ; initialize counter bis.w #LPM0+GIE,SR ; Enter LPM0 w/ interrupt jmp $ ; Loop forever; interrupts do all ; Watchdog Timer interrupt service routine ; WDT_ISR: xor.b #0x20,&P4OUT ; pulse buzzer dec.w &cnt ; decrement counter jne WDT_exit mov.w #COUNT,&cnt ; initialize counter xor.b #0x01,&P1OUT ; toggle P1.0 WDT_exit: reti ; return from interrupt .sect “.int10” ; MSP430 RESET Vector .word WDT_ISR ; Watchdog ISR .sect “.reset” ; MSP430 RESET Vector .word RESET ; Power Up ISR .end Labels Instructions Comments Directives Adapted from notes from BYU ECE124 Adapted from notes from BYU ECE124 8
PAGE – 9 ============
Common Assembler Directives Mnemonic and Syntax Description .bss symbol, size in bytes [, alignment] Reserves size bytes in the .bss (uninitialized data) section .sect “section name ” Assembles into a named (initialized) section .text Assembles into the .text (executable code) section .byte value1[, , valuen] Initializes one or more successive bytes in the current section .string “string 1″[, , “string n”] Initializes one or more text strings .word value1[, , valuen] Initializes one or more 16-bit integers .align [size in bytes ] Aligns the LC on a boundary specified by size in bytes; must be a power of 2; defaults to word (2 byte) .def symbol1[, , symboln] Identifies one or more symbols that are defined in current module and that can be used in other modules .include [“] filename [“] Includes source statements from another file .ref symbol1[, , symboln] Identifies one or more symbols used in the current module that are defined in another module symbol .equ value Equates value with symbol symbol .set value Equates value with symbol .cdecls [options ,] ” filename ” Share C headers between C and assembly code .end Ends program Adapted from notes from BYU ECE124 9
PAGE – 10 ============
CCS Window Ð C/C++ Perspective Independent debugging and Programming view 1-click project debug Project View ¥! List of Projects Code Window ¥! Breakpoints ¥! Syntax highlighting Console Build information Problems View ¥! Information ¥! Warnings ¥! Errors Adapted from notes from BYU ECE124 10
PAGE – 11 ============
Assembly List File !!A line in a listing file has four fields: Ð!Field 1: contains the source code line counter Ð!Field 2: contains the section program counter Ð!Field 3: contains the object code Ð!Field 4: contains the original source statement. Adapted from notes from BYU ECE124 11
23 KB – 53 Pages