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

Microcomputer Principles and Applications - Lab 6 | ECEN 3213, Lab Reports of Electrical and Electronics Engineering

Material Type: Lab; Subject: Electrical and Computer Engineering ; University: Oklahoma State University - Stillwater; Term: Spring 2005;

Typology: Lab Reports

Pre 2010

Uploaded on 03/19/2009

koofers-user-lpi-1
koofers-user-lpi-1 🇺🇸

10 documents

1 / 4

Toggle sidebar

Related documents


Partial preview of the text

Download Microcomputer Principles and Applications - Lab 6 | ECEN 3213 and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity! ECEN 3213 Spring 2005 Lab 6 Due in Lab Section, Feb. 28, Mar. 2 Objective. Understand stack data structures. Discussion. A stack data structure is convenient for temporary data storage. Rather than permanently allocating RAM locations for several different variables, the same RAM locations can be used repeatedly for different purposes. This particularly important for embedded proces- sors that usually have only a small number of registers and RAM locations. The stack pointer register, SP, is dedicated to implement a first-in-last-out (FILO) data structure. A data item is added to the stack with a push operation. A pull operation retrieves data items in the reverse order as pushed onto the stack. The 6811 instruction set provides special instructions to push, pull the A,B,X and Y registers. psha This instruction pushes the 8-bit contents of the A-register onto the stack. It is equivalent to sta [SP] store A at address in SP des decrement SP where sta [SP] is not really a legal instruction (the X or Y registers and indexed addressing could be used instead). The pshb instruction works the same way to push the contents of the B-register on the stack. pshx This instruction pushes the 16-bit contents of the X-register onto the stack. It is equivalent to stx [SP] store X at address in SP des decrement SP des decrement SP again and pshy works the same way to push the contents of Y onto the stack. The pull operations are the reverse of the push operations. pulaECEN 3213 Spring 2005 Lab 6 January 27, 2005 page 1 of 4 This instruction pulls 8-bits from the top of the stack and loads it into the A-register. It is equivalent to ins increment SP lda [SP] load A from address in SP where lda [SP] is not really a legal instruction (the X or Y registers and indexed address- ing could be used instead). The pulb instruction works the same way to pull the contents of the top of the stack into the B-register. pshx This instruction pulls 16-bits from the top of the stack and loads it into the X-register. It is equivalent to ins increment SP ins increment SP again ldx [SP] load X from address in SP and puly works the same way to pull the contents of the top of the stack into Y. Stack Initialization. Because the stack grows downward in memory, the stack pointer is usually initialized to the highest RAM address available. On the 68HC711E, there are 512 bytes of RAM extending from $0000 to $01FF. lds #$01FF set SP to top of RAM Stack Overflow. As the stack grows downward in memory, it can overwrite memory locations reserved for variables. There is no automatic mechanism to prevent this from happening. Software techniques must be used to insure data integrity. Before a push instruction, the program- mer must add extra code to check that the SP register contents point to a valid address. The 6811 instruction set does not allow comparisons or conditional branches using the SP register. Thus, it is necessary to move the stack pointer contents to another register as in the following example. tsx transfer SP + 1 to X cpx #$0100 bls err branch on stack overflow error psha In this example, the lowest allowed stack storage is at $0100. An attempt to push a data item below $0100 will cause a branch to the “err” location instead. Stack overflow check- ing is not always necessary although it might be a good idea while debugging code. Over- flow checking requires three extra instructions (tsx, cpx, bls) which greatly reduces the efficiency of stack operations. If there is enough RAM available, stack overflow is unlikely to occur and the overflow check is usually not done. Stack underflow is also possible if more operands are pulled from the stack than were pushed. Underflow checking is done by adding extra code before each pull instruction.ECEN 3213 Spring 2005 Lab 6 January 27, 2005 page 2 of 4
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved