Docsity

HCS12 Instruction Set - Microprocessor Systems - Lecture Notes | ECE 4436, Study notes of Microprocessors

Partial preview of the text

Download HCS12 Instruction Set - Microprocessor Systems - Lecture Notes | ECE 4436 and more Study notes Microprocessors in PDF only on Docsity!

Chap. 7: HCS12 Instruction Set

Dept. of Electrical & Computer Engineering

University of Houston

Table 7-

Instruction

Categories

Load Register Instructions

Table 7-6 Store

Register

Instructions

Store Register Instructions

ECE 4436ECE 4436

Ex. 7-1 Load and

Store Instructions,

show addr mode

syntax

Example 7-1 Load and Store Register Instructions Rel. Loc Obj. code Source line


5 ; Immediate addressing 6 000000 8640 ldaa #64 ; Decimal 64 -> A 7 000002 CF09 02 lds #$0902 ; $0902 -> SP 8 ; Direct addressing 9 000005 D664 ldab $64 ; ($0064) -> B 10 000007 5A65 staa $65 ; A -> ($0065) 11 ; Extended addressing 12 000009 B612 34 ldaa $1234 ; ($1234) -> A 13 00000C FE12 34 ldx $1234 ; ($1234:1235) -> X 14 00000F 7E08 00 stx $0800 ; X -> ($0800) 15 ; Indexed addressing 16 000012 E6E0 17 ldab 23,x ; (X+23) -> B 17 000015 6B40 stab ,y ; B -> (Y) 18 000017 A63E ldaa 2,x- ; (X) -> A 19 ; X-2 -> X (Auto decrement) 20 ; Indexed-indirect addressing 21 000019 EEEF ldx [d,y] ; ((D+Y)) -> X 22 00001B A6E3 0100 ldaa [$100,x]; ((X+$0100)) -> A

Stack Instructions

  • Stack Pointer (SP) – 16-bit address register that points to

the value on “top” of the stack.

  • Stack “grows” toward lower addresses.
  • “Push” operation puts new value on top of stack:
    • Decrement SP
    • Store value where SP points
  • “Pull” (“pop”) operation take value off top of stack:
    • Load value from where SP points
    • Increment SP

Uses for the Stack

  • Temporarily saving a few bytes of data from registers,

then restoring later.

  • Allocating data space for temporary variables such as

“automatic” variables in C.

  • Saving the return address when the program calls a

subroutine. This is done automatically by the jump-to-

subroutine instruction (JSR or BSR).

  • Similarly, saving the return address when an interrupt

occurs.

  • Normally, stack operations must be balanced, push

operations matched by pull/pop operations.

Simple Stack Example

Calling Subroutines

To call a subroutine:

  • JSR subr – Jump to subroutine (many addressing modes)
  • BSR subr – Branch to subroutine (9-bit relative)
      1. Pushes PC (return address, of next instruction) onto

stack.

    1. Starts execution at target address (subr).

Last instruction in subroutine:

  • RTS – Return from subroutine
    • Pops address off stack into PC, thus resuming

execution following the original JSR/BSR.

Calling Subroutines

jsr printf ; call print function

printf:

rts ; return

Address of this next

instruction (PC) is pushed

by jsr instruction.

Top of the stack is popped into the PC by

the rts instruction, returning execution

to the instruction following the jsr.

Load Effective Address Instructions

Ex. 7-11 Load

Eff Addr

Instructions

Clear and Set Instructions

Table 7-10 Clear and

set instructions

Fig. 4-1 MC9S12C

family block diagram

MC9S12C

Hardware Memory Map for 9S12C

Fig 6-

Memory map

I/O registers “appear”

at these addresses.