1. Trang chủ
  2. » Giáo án - Bài giảng

Kĩ thuật vi xử lý Lecture4_MSP430 Programming

102 13 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 102
Dung lượng 1,18 MB

Nội dung

Kĩ thuật vi xử lý Lecture4_MSP430 Programming

Lecture – MSP430 Compiler / Assembler / Linker / Debugger Topics to Cover…  High Level vs Assembly  MSP430 Assembler  Assembly Code  Assembly Process  Assembly Directives  Linker  Flashing LEDs  Systematic Decomposition  Assembly and C  Quick Reference: Assembly Instructions Lecture - MSP430 Assembler Moving Up Levels of Abstraction Problems Algorithms Language Assembly code Machine (ISA) Architecture Machine code Microarchitecture MSP430 Architecture Circuits Logic gates, multiplexers, memory, etc Devices Lecture - MSP430 Assembler Transistors High Level vs Assembly 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 Lecture - MSP430 Assembler High Level vs Assembly Why Assembly Code?  Allows us to work at a slightly higher level than machine language  Allows us to use symbolic names for opcodes  Allows us to use symbolic names for memory locations  SUM, PRODUCT  Don’t need to know every address of every storage location  Calculates addresses for us – really a big deal!  Helps to allocate memory locations  Provides additional error checking Lecture - MSP430 Assembler MSP430 Assembler Assembler An assembler outputs an object file An assembler translates a program into machine code s43 r43 An assembly program is a text file containing assembly An object file is input to a linker program instructions, directives, macros, and comments Lecture - MSP430 Assembler MSP430 Assembler Assembly Syntax  Each assembly line begins with either a label, a blank (tab), or a semicolon  Each line has four fields: {label[:]} mnemonic {operand list} {;comment}  Some line examples are: public memcpy memcpy:mov.w memcpy_loop: 2(SP),R13 ;Number of bytes to fill rra.w R13 ; byte -> word tst.w R13 ; count = ? jeq memcpy_end; if so, quit dec.w R13 mov.w @R14+,0(R12); copy word incd.w R12 jmp memcpy_loop; loop ; else decrement counter ; increment destination memcpy_end: ret end Lecture - MSP430 Assembler Assembly Code 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  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 Lecture - MSP430 Assembler Assembly Code 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  Assembler directive  Macro directive  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 Lecture - MSP430 Assembler Assembly Code Constants / Expressions   Constants  The assembler maintains constants internally as signed (2’s complement) or unsigned numbers  Constants are not sign extended  The pound sign (#) precedes a constant in an instruction  Types of constants:  Decimal: needs nothing followed decimal digits: 100  Hexadecimal: hexadecimal digits followed by ‘H’ (or ‘h’) or preceded by ‘0x’ (ie, 78h, 0x78)  Binary: binary digits followed by suffix B (or b) (ie 0000b, 11110000B) Expressions  An expression is a constant, a symbol, or a series of constants and symbols separated by arithmetic operators  An expression evaluates to a value  The precedence order of expression evaluation is  First, evaluate parenthesized expressions  Second, evaluate operators according to precedence groups  Third, when parentheses and precedence groups not determine the order of expression evaluation, the expressions are evaluated from left to right Lecture - MSP430 Assembler 10 Emulated Instructions Enable General Interrupts  EINT Enable (general) interrupts  Syntax EINT  Operation → GIE or (0008h OR SR −> SR)  Emulation BIS #8,SR  Description All interrupts are enabled The constant register SR are logically ORed The result is placed into the SR  Status Bits Status bits are not affected  Note: The instruction following the enable interrupt instruction (EINT) is always executed, even if an interrupt service request is pending #08h and the status when the interrupts are enable Lecture - MSP430 Assembler 88 Emulated Instructions Increment Destination  INC Increment destination word or byte  Syntax INC dst or INC.W dst  Operation dst + −> dst  Emulation ADD #1,dst  Description The destination operand is incremented by one The original contents are lost  Status Bits N: Set if result is negative, else reset Z: Set if dst contained 0FFFFh, else reset C: Set if dst contained 0FFFFh, else reset  Example V: Set if dst contained 07FFFh, else reset INC.B STATUS Lecture - MSP430 Assembler 89 Emulated Instructions Double-increment Destination  INCD Double-increment destination  Syntax INCD{.W or B} dst  Operation dst + −> dst  Emulation ADD{.W or B} #2,dst  Description The destination operand is incremented by two The original contents are lost  Status Bits N: Set if result is negative, else reset Z: Set if dst contained 0FFFEh, else reset C: Set if dst contained 0FFFEh or 0FFFFh, V: Set if dst contained 07FFEh or 07FFFh,  Example INCD R5 Lecture - MSP430 Assembler else reset else reset ; increment r5 by 90 Emulated Instructions Invert Destination  INV Invert destination word or byte  Syntax INV{.W or B} dst  Operation NOT.dst −> dst  Emulation XOR{.W or B} #0FFFFh,dst  Description The destination operand is inverted The  Status Bits N: Set if result is negative, else reset original contents are lost Z: Set if dst contained 0FFFFh, else reset Set if dst contained 0FFh, else reset C: Set if result is not zero, else reset V: Set if overflow, else reset  Example INV R5 ; Invert R5, R5 = 0FF51h Lecture - MSP430 Assembler 91 Emulated Instructions No Operation  NOP No operation  Syntax NOP  Operation None  Emulation MOV #0, R3  Description No operation is performed The instruction elimination of instructions during the software check or for defined waiting times  Status Bits Status bits are not affected  Examples MOV #0,R3 JMP $+2 ; cycles, word MOV #100,R3 ; cycles, words Lecture - MSP430 Assembler may be used for the ; cycle, word 92 Emulated Instructions Pop TOS to Destination  POP Pop word or byte from stack to destination  Syntax POP{.W or B} dst  Operation @SP −> temp SP + −> SP temp −> dst  Emulation MOV{.W or B} @SP+,dst  Description The stack location pointed to by the stack pointer (TOS) is moved to the destination The stack pointer is incremented by two afterwards  Status Bits Status bits are not affected  Note: The system stack pointer (SP) is always incremented by two, independent of the byte suffix Lecture - MSP430 Assembler 93 Emulated Instructions Return from Subroutine  RET Return from subroutine  Syntax RET  Operation @SP→ PC SP + → SP  Emulation MOV @SP+,PC  Description The return address pushed onto the stack by a CALL instruction is moved to the program counter The program continues at the code address following the subroutine call Status Bits Status bits are not affected  Lecture - MSP430 Assembler 94 Emulated Instructions Rotate Left Arithmetically  RLA Rotate word or byte left arithmetically  Syntax RLA{.W or B} dst  Operation C ← MSB ← MSB−1 LSB+1 ← LSB ←  Emulation ADD{.W or B} dst,dst  Description The destination operand is shifted left one position The MSB is shifted into the carry bit (C) and the LSB is filled with The RLA instruction acts as a signed multiplication by An overflow occurs if the result has Status Bits N: Set if result is negative, else reset  changed sign Z: Set if result is zero, else reset C: Loaded from the MSB V: Set if an overflow, else reset Lecture - MSP430 Assembler 95 Emulated Instructions Rotate Left Through Carry  RLC Rotate word or byte left through carry  Syntax RLC{.W or B} dst  Operation C ← MSB ← MSB−1 LSB+1 ← LSB ← C  Emulation ADDC{.W or B} dst,dst  Description The destination operand is shifted left one is shifted into the LSB and the MSB is shifted into the carry bit (C) Status Bits N: Set if result is negative, else reset  position The carry bit (C) Z: Set if result is zero, else reset C: Loaded from the MSB V: Set if an arithmetic overflow, else reset Lecture - MSP430 Assembler 96 Emulated Instructions Subtract Borrow from Destination  SBC Subtract borrow (¬carry) from destination  Syntax SBC{.W or B} dst  Operation dst + 0FFFFh + C −> dst  Emulation SUBC{.W or B} #0,dst  Description The carry bit (C) is added to the destination previous contents of the destination are lost Status Bits N: Set if result is negative, else reset  operand minus one The Z: Set if result is zero, else reset C: Set if there is a carry, else reset Set to if no borrow, reset if borrow V: Set if an arithmetic overflow, else reset  Example SBC 2(R12) SUB @R13,0(R12) ; Subtract LSDs ; Subtract C MSD Lecture - MSP430 Assembler 97 Emulated Instructions Set Carry Bit  SETC Set carry bit  Syntax SETC  Operation −> C  Emulation BIS #1,SR  Description The carry bit (C) is set  Status Bits N: Not affected Z: Not affected C: Set V: Not affected  Example SETC Lecture - MSP430 Assembler ; set carry = 98 Emulated Instructions Set Negative Bit  SETN Set negative bit  Syntax SETN  Operation −> N  Emulation BIS #4,SR  Description The negative bit (N) is set  Status Bits N: Set Z: Not affected C: Not affected V: Not affected  Example SETN Lecture - MSP430 Assembler 99 Emulated Instructions Set Zero Bit  SETZ Set zero bit  Syntax SETZ  Operation −> Z  Emulation BIS #2,SR  Description The zero bit (Z) is set  Status Bits N: Not affected Z: Set C: Not affected V: Not affected  Example SETZ Lecture - MSP430 Assembler 100 Emulated Instructions Test Destination  TST Test destination word or byte  Syntax TST{.W or B} dst  Operation dst + 0FFFFh +  Emulation CMP{.W or B} #0,dst  Description The destination operand is compared with set according to the result The destination is not affected Status Bits N: Set if destination is negative, else reset  zero The status bits are Z: Set if destination contains zero, else reset C: Set V: Reset  Example TST R7 Lecture - MSP430 Assembler ; Test R7 101 Summary Lecture - MSP430 Assembler 102 ... ISA  Very ISA-dependent  Each instruction specifies a single ISA instruction  Makes low level programming more user friendly  More efficient code Lecture - MSP430 Assembler High Level vs Assembly... DEBUGGING  Reading: MSP430 IAR Assembler Reference Guide Lecture - MSP430 Assembler 19 Assembly Programming Example: Decimal/Integer Addition of 32-bit Numbers  Problem  Write an assembly program... We are interested in:  How a high-level language uses low-level language features?  C: System programming, device drivers, …  Use of addressing modes by compilers  Parameter passing in assembly

Ngày đăng: 20/02/2022, 15:08

w