Physics 413 Chapter 2: HCS 12 Assembly Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Physics 413 Chapter 2: HCS 12 Assembly Programming

Description:

Physics 413 Chapter 2: HCS 12 Assembly Programming My First Assembly Program Program adds two 16-bit numbers stored at $1000 - $1001 and $1002 - $1003 and stores the ... – PowerPoint PPT presentation

Number of Views:73
Avg rating:3.0/5.0
Slides: 24
Provided by: AsifS1
Category:

less

Transcript and Presenter's Notes

Title: Physics 413 Chapter 2: HCS 12 Assembly Programming


1
Physics 413Chapter 2 HCS 12 Assembly Programming
2
My First Assembly Program
  • Program adds two 16-bit numbers stored at 1000 -
    1001 and 1002 - 1003 and stores the sum at
    1010 - 1011
  • org 2000
  • ldd 1000
  • addd 1002
  • std 1010
  • end

3
Assembler Directives and more
  • org
  • end
  • equ
  • db
  • fcc
  • Examples
  • alpha equ 1.7
  • string fcc hello!
  • array db 3, 8, 23, 11, 57, 12, 47

4
DAA
  • DAA Decimal Adjust Accumulator
  • Converts binary addition of BCD numbers into BCD
  • format
  • What will the contents of A be with without DAA
    ?
  • LDAA 23 86 23
  • ADDA 48 8B 48
  • DAA 19
  • SWI 3F

5
DAA
  • LDAA 23
  • ADDA 48
  • DAA
  • SWI
  • Without DAA the contents of A 6B
  • With DAA the contents of A 71

6
Multiplication and Division
  • mul A B stored in AB
  • emul D Y stored in YD
  • ediv 32-bit number YD divided by 16-bit X and
    quotient stored in Y and remainder in D

7
emacs
  • Multiply and Accumulate
  • Multiplies two 16-bit numbers and adds a 32-bit
    number.
  • 16-bit numbers are pointed to by index registers
    X and Y.
  • Result is stored where the 32-bit constant was
    stored!
  • 16-bit number takes up two memory locations
  • 32-bit number takes up 4 memory locations.
  • Useful in signal processing and other
    computational problems
  • Rewrite ax2 bx c as x(axb) c for emacs
    format
  • (Mx . Mx1 )(My . My1 ) (M . M 3) ? (M .
    M 3)

8
A Fork in the Road
  • LDAB 13
  • here ADDA 24
  • DEC B
  • BNE here
  • SWI
  • BNE is the new instruction. Branch if not equal
    to zero.

9
Branches Galore
  • Mnemonic Description of Criteria
  • BCC Branch if Carry Clear
  • BCS Branch if Carry Set
  • BEQ Branch if Equal to Zero
  • BNE Branch if Not Equal to Zero
  • BRA Branch Always
  • Note Familiarize yourself with other related
    instructions like DBNE, JMP, BSR, and JSR

10
Dare to Compare !
  • here LDAA E3
  • CMPA 50
  • BNE here
  • SWI
  • Temperature sensor reading is stored at memory
    location 0050 and compared with a danger limit of
    E3 .

11
Bit Condition Branch Instruction
  • again brclr 1000,84,again
  • ldd 70
  • The mask is 84. The bits to be checked are bit
    2 and bit 7. The contents of memory location
    1000 will be checked and when bits 2 and 7 are
    both 0 the instruction ldd 70 will be executed .
    If both bits 2 and 7 are not 0 then the program
    will keep checking by going back to again.

12
Bit Condition Branch Instruction
  • again brset 1000,84,again
  • ldd 70
  • The mask is 84. The bits to be checked are bit
    2 and bit 7. The contents of memory location
    1000 will be checked and when bits 2 and 7 are
    both 1 the instruction ldd 70 will be executed .
    If both bits 2 and 7 are not 1 then the program
    will keep checking by going back to again.

13
ASLA
  • ASLA Arithmetic Shift Left Accumulator A.
  • It shifts all the 8 bits of accumulator A one bit
    to the LEFT. The rightmost bit
    becomes 0 and the leftmost bit ends up as the
    carry bit of CCR

C
0
14
Logical AND
  • What is the outcome of ANDA 4C if accumulator
    A contains 3 A ?

15
Logical AND
  • 3A 0011 1010
  • 4C 0100 1100
  • _________________________
  • 0000 1000
  • Hence A will contain 08 after the AND operation

16
Bit Flipping and Testing
  • bclr 0,y,44 clears bits 2 and 6 of the contents
    of the memory location pointed to by the index
    register Y.
  • bset sets the bits designated by the mask.
  • bita 22 tests bits 1 and 5 of accumulator A and
    updates the Z and N flags of the CCR but does not
    change the contents of the accumulator.

17
Delay Loop
  • DELAY LDX FFFF
  • AGAIN DEX
  • BNE AGAIN
  • SWI

18
Delay Loop Subroutine
  • here JSR DELAY
  • LDAA E3
  • CMPA 50
  • BNE here
  • SWI
  • .
  • .
  • .
  • DELAY LDX FFFF
  • AGAIN DEX
  • BNE AGAIN
  • RTS

19
Stack
  • Stack is the area of RAM pointed to by the 16-bit
    Stack Pointer (SP)
  • LDS functions like LDX
  • LDS 5C42 The number 5C42 is loaded into SP
  • LDS 5C42 Numbers from 5C43 and 5C42 loaded
  • LDS 5C Numbers from 005D and 005C loaded

20
Push and Pull
  • PSHA A MSP SP - 1 SP
  • PULA SP 1 SP MSP
    A

21
Predict the Outcome!
  • PSHA
  • PSHB
  • PULA
  • PULB

22
Solution
  • Congratulations, if you said the contents of A
    and B will be swapped and , perhaps more
    importantly, the value of the stack pointer will
    be restored to its original value before this
    program segment was run.

23
Detailed Explanation
  • Suppose that SP was pointing at 00D6 (stack).
    PUSHA stores A into 00D6. Then PUSHB stores B
    into 00D5. At this point SP 00D4. Then PULA
    pulls 00D5 (which contains B) and stores it into
    A. Finally, PULB pulls 00D6 (which contains A)
    and stores it into B. We end up swapping A and
    B. At this point SP 00D6, its original value.
Write a Comment
User Comments (0)
About PowerShow.com