lecture02 - 0306-250 Assembly Language Programming Lecture...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-250 Assembly Language Programming Lecture Two: • • • • • • • Assembler directive syntax Registers Assembly language syntax Data sizes Basic data movement instructions Basic arithmetic instructions Example arithmetic computations HCS12 Assembler Directive Syntax [Label] Directive[.Size] Parameter • Label: optional name (beginning with a letter) Format Suggestions – Left margin • Directive: assembler instruction Format Suggestions – Tabbed to left-align with instructions – Upper case • Parameter: immediate value 2 TITLE ″Title″ TITLE directive • Specifies title of the program • Title: Text string enclosed in quotation marks 3 END END directive • Specifies where the program ends (i.e., where assembler should stop) 4 LABEL EQU Value EQU (Equate) directive • Text substitution by assembler LABEL replaced with Value throughout • May be used to establish constant for assembler – Note: no memory allocated or assigned – Text substitution before assembly 5 HCS12 CPU Registers • Two 8-bit accumulators: A, B Can be concatenated as 16-bit accumulator: D • Two 16-bit index registers: X, Y • 16-bit stack pointer: SP • 16-bit program counter: PC • 8-bit condition code register: CCR S12CPUV2 Reference Manual, p. 21 6 HCS12 Assembly Instruction Syntax [Label] Mnemonic [Operand1[,Operand2]] • Label: optional name (beginning with a letter); only first 8 characters significant • Mnemonic: assembly language instruction • Operand: data source – Memory location – Register – Immediate value 7 HCS12 Number Specification • Decimal – No prefix symbol – Examples: 0, 15, 256, etc. • Binary – % prefix symbol – Examples: %0, %1111, %100000000, etc. • Hexadecimal – $ prefix symbol – Examples: $0, $0F, $0100, etc. 8 HCS12 Operand Specification • Memory location – Address (number or label) – Examples: 0, $22000, MAIN • Register contents – Name – Examples: X, Y, SP, PC, etc. • Immediate value – # prefix with value – Examples: #0, #%00100000, #$FF 9 HCS12 Data Sizes • Byte – 8 bits – Symbol: B • Word – 16 bits – Symbol: W • Long Word – 32 bits – Symbol: L 10 General Classes of Assembly Language Instructions • Data Movement • Data Operation – Arithmetic – Logical – Shift • Program Control – Unconditional – Conditional 11 Data Movement Instructions “Load” and “store” instructions • Highly used: get operands to/from registers • Most versatile: widest variety of operands • More at “copy”: source operand unchanged F For now, consider only most basic and common. • • • • • • LDAA, STAA LDAB, STAB LDD, STD LDS, STS LDX, STX LDY, STY 12 LDAA Source S12CPUV2 Reference Manual, p. 214 13 STAA Destination S12CPUV2 Reference Manual, p. 279 14 LDD Source S12CPUV2 Reference Manual, p. 216 15 STD Source S12CPUV2 Reference Manual, p. 281 16 HCS12 Load and Store Instructions S12CPUV2 Reference Manual, pp. 56-57 17 HCS12 Clear Instructions S12CPUV2 Reference Manual, pp. 63 and 149 18 General Classes of Assembly Language Instructions • Data Movement • Data Operation – Arithmetic – Logical – Shift • Program Control – Unconditional – Conditional 19 Basic Arithmetic Instructions • Three general classifications – Binary (signed) – BCD (binary coded decimal) – Extended precision (multiple elements) • Many variations on basic operations (e.g., add, subtract, etc.) F For now, consider only binary arithmetic. • ADDA, ADDB, ADDD, SUBA, SUBB, and SUBD • ABA, ABX, ABY, and SBA • NEG, NEGA, and NEGB 20 Add and Subtract Instructions S12CPUV2 Reference Manual, p. 59 21 ADDReg Source: Add Source to Reg S12CPUV2 Reference Manual, p. 105 22 SUBReg Src: Subtract Src from Reg S12CPUV2 Reference Manual, p. 286 23 ABReg: Add B to Reg S12CPUV2 Reference Manual, p. 100 24 SBA: Subtract B from A S12CPUV2 Reference Manual, p. 272 25 Negate Instructions S12CPUV2 Reference Manual, pp. 63 and 240 26 Multiply and Divide Instructions • ADD and SUB: size consistent – Same size source and destination – Example: byte + byte ® byte • Not so with multiply and divide – Different size source and destination – Example: byte ´ byte ® word For now, consider only size-consistent instructions. 27 Multiply or Divide by Power of Two • Shift left n bits – Multiply by 2n – Example: 25 << 1 ® 50 = 25 ´ 2 • Arithmetic shift right n bits – Divide by 2n – Example: 26 >> 1 ® 13 = 26 ¸ 2 28 Arithmetic Shift Instructions S12CPUV2 Reference Manual, p. 66 29 ASLA S12CPUV2 Reference Manual, p. 112 30 ASRA S12CPUV2 Reference Manual, p. 116 31 Arithmetic Expression Example • Compute 13 - 16 + 2 ´ 12 + 3 ´ 7 – Each term for addition or subtraction must be in a register – Use immediate values in instructions – Only byte operations can be used ; 13 – 16 ldaa #13 ldab #16 sba ; 13 - 16 + 2 x 12 ldab #12 aslb aba ; 13 - 16 + 2 x 12 + 3 x 7 ldab #7 aslb addb #7 aba ; 13 ; 16 ; subtract ; 12 ; 2 x 12 ; add ; ; ; ; 7 2 x 7 3 x 7 add 32 ...
View Full Document

This note was uploaded on 05/06/2010 for the course EECC 0306-250 taught by Professor Roymelton during the Fall '10 term at RIT.

Ask a homework question - tutors are online