lecture_note4

lecture_note4 - CpE 390 Microprocessor Systems Lecture 4...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Stevens Institute of Technology 1 CpE 390 Microprocessor Systems Lecture 4 Advanced Assembly Programming (1)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introduction - Program = data structures + algorithm - Data structures to be discussed 1. stacks : a first-in-last-out data structure 2. arrays : a set of elements of the same type 3. strings : a sequence of characters terminated by a special character Stack top element low address Stack pointer Push Pop (or Pull) A reserved RAM area in main memory where program perform push or pull operations stack overflow: push too much stack underflow: pull too much bottom element high address Figure 4.1 Diagram of the 68HC12 stack Stevens Institute of Technology 2
Background image of page 2
Stevens Institute of Technology 3 68HC12 Support for the Stack Data Structure - A 16-bit stack pointer (SP) - Instructions and addressing mode Table 4.1 68HC12 push and pull instructions and their equivalent load and store instructions Mnemonic psha pshb pshc pshd pshx pshy pula pulb pulc puld pulx puly Function push A into the stack push B into the stack push CCR into the stack push D into stack push X into the stack push Y into the stack pull A from the stack pull B from the stack pull CCR from the stack pull D from the stack pull X from the stack pull Y from the stack Equivalent instruction staa 1, -SP stab none std 2, -SP stx sty ldaa 1, SP+ ldab ldd 2, SP+ ldx ldy
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Stevens Institute of Technology 4 68HC12 Memory Map $0000 $FFFF $0800 $0BFF $7FFF $1000 $09FF $0A00 D-Bug 12 monitor Internal registers I/Os Stack area/ user memory EPROM User program Stack area SP = $0A00 On-chip SRAM Stack area External SRAM SP = $8000
Background image of page 4
Stevens Institute of Technology 5 68HC12 Support for the Stack Data Structure •U s a g e Saving the return address for a subroutine call A good place to hold local variables Context switch When multiple tasks exit, the operating system would switch from one task to another based on different schedule algorithm Reasons Dynamic allocation/release allows for reuse of memory Limited scope of access provide data protection Only the program that created the local variables can access it The # of variables is limited only be the size of the stack allocation, more than registers
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Stevens Institute of Technology 6 Indexable Data Structures - Vectors and matrices are indexable data structures. - The first element of a vector is associated with the index 0 in order to facilitate the address calculation. - Assemblers directives db, dc.b, fdb are used to define arrays of 8-bit elements. - Assemblers directives dw, dc.w, and fdb are used to define arrays of 16-bit elements.
Background image of page 6
Stevens Institute of Technology 7 Arrays Are indexable data structure, usually zero-origin indexing Are made up of elements of same types and precision One-dimentional=>vector, Two-dimentional => matrics Vectors Define a vector In C: construct char data[4] = {0x05, 0x06,0x0A, 0x09}; In Assembly: data fcb(/db/dc.b) $05, $06, $0A, $09 ; byte array data1 fdb(/fw/dc.w) $0506, $0A09 ; word array Access the ith element of a byte array LDAB #i ; load index i to B LDX #data ; load base address LDAA B,X ; read the ith element base i base+i 1 byte
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 27

lecture_note4 - CpE 390 Microprocessor Systems Lecture 4...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online