Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Assembly Language Programming Cheat Sheet, Cheat Sheet of Assembly Language Programming

Review study guide and cheat sheet on Assembly Language Programming

Typology: Cheat Sheet

2019/2020

Uploaded on 11/27/2020

ekaashaah
ekaashaah 🇺🇸

4.4

(40)

274 documents

1 / 53

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Assembly Language
Programming
EE3376
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35

Partial preview of the text

Download Assembly Language Programming Cheat Sheet and more Cheat Sheet Assembly Language Programming in PDF only on Docsity!

Assembly Language

Programming

EE

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

Assembler Syntax

l Each assembly line begins with either a label, a

blank (tab), an asterisk, or a semicolon

l Each line has four fields:

{label[:]} mnemonic {operand list} {;comment}

l 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

Symbols / Labels

l Symbols

  • Symbols are used as labels, constants, and substitution values
  • Symbols are stored in a symbol table
  • A symbol name

l is a string of up to 200 alphanumeric characters (A-Z, a-z, 0-9, $, and _)

l cannot contain embedded blanks

l first character cannot be a number

l case sensitive

  • Symbols used as labels become symbolic addresses that are associated with locations in the program

l 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.

Assembler Directives

l Assembly directives are used to specify:

– Starting addresses for programs

– Starting values for memory locations

– Specify the end of program text.

;******************************************************************************* ; CS/ECEn 124 Example Code ;******************************************************************************* .cdecls C,LIST, "msp430x22x4.h“ ; include C header COUNT .equ 2000 ;------------------------------------------------------------------------------ .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 bis.w #LPM0+GIE,SR ; Enter LPM0 w/ interrupt jmp $ ; Loop forever; interrupts do all .sect ".reset" ; MSP430 RESET Vector .word RESET ; Power Up ISR .end Directives

Current Location Counter

Assembly Code Example

;******************************************************************************* ; CS/ECEn 124 Lab 4 - morse.asm: Student Code ;******************************************************************************* .cdecls C,LIST, "msp430x22x4.h“ ; 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. 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

8 Adapted from notes from BYU ECE124Adapted from notes from BYU ECE

CCS Window – C/C++ Perspective

Independent debugging

1-click project debug^ and Programming view

Project View

  • List of Projects

Code Window

  • Breakpoints
  • Syntax highlighting

Console

Build information

Problems View

  • Information
  • Warnings
  • Errors

Assembly List File

l 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.

MSP 430 Micro-Architecture

Memory Address Register

Arithmetic Logic Unit

Program Counter

Address Bus

Data Bus

Condition Codes Memory

Port 1 Output

Instruction Register

Source Operand

Destination Operand

MSP 430 Data Storage

n The MSP430 CPU has 64KB memory space

and 16 registers for data storage

n R0 (PC) – Program Counter

n This register always points to the next instruction to be fetched

n R1 (SP) – Stack Pointer

n The MSP430 CPU stores the return address of routines or interrupts on the stack n User programs store local data on the stack

n R2 (SR/CG1) – Status Register

n The status of the MSP430 CPU is defined by a set of bits contained in register R

MSP 430 Registers

l R4-R15 – General Purpose registers

– The general purpose registers R4 to R15 can be used

as data registers, data pointers and indices.

– They can be accessed either as a byte or as a word

– Instruction formats support byte or word accesses

– The status bits of the CPU in the SR are updated

after the execution of a register instruction.

MSP430G2553 Memory Map

Examples MOV.w #0x08,R5! !; move source to destination! !! !; assign a hexadecimal value 0x08 to Register R5! AND.w #0x00,R6! !; bitwise AND source with destination! !! !; whatever value in R6 is ANDed with 0 -> R6=0! ADD.w #0x03,R6! !; add source to destination! !! !; R6 = R6+3 = 0+3 = 3! SUB.w !R6, R5! !; subtract source from destination! !! !; R5 = R5-R6 = R5+(Not R6)+1 = 8-3 = 5! XOR.w !R6, R5! !; bitwise XOR source with destination! !! !; R5 = 0011 XOR 0101 = 0110 = 6! BIC.w !#0x03, R5 !; clear bits in destination! !! !; (Not 0011) AND 0110 = 1100 AND 0110 = 0100 = 4! BIS.w !#0x08, R5 !; set bits in destination! !! !; 1000 OR 0100 = 1100 = 12! BIT.w !#0x08, R5 !; test bits in destination! !! !; 1000 AND 1100 = 1000 -> Bit 3 is not zero! CMP.w !R6, R5! !; compare source to destination! !! !; R5-R6 = 12-6 = 6 greater than 0, so R5 > R6! 19

Format II: 7 Single Operand Instructions l Single operand instructions:

Mnemonic Operation Description

Logical and register control instructions

RRA(.B or .W) dst MSB → MSB → …

LSB → C

Roll destination right

RRC(.B or .W) dst C → MSB → …LSB → C Roll destination right through carry

SWPB( or .W) dst Swap bytes Swap bytes in destination

SXT dst bit 7 → bit 8…bit 15 Sign extend destination

PUSH(.B or .W) src SP-2 → SP, src → @SP Push source on stack

Program flow control instructions

CALL(.B or .W) dst SP-2 → SP,

PC+2 → @SP

dst → PC

Subroutine call to destination

RETI @SP+ → SR, @SP+ → SP Return from interrupt

20