Lecture 17 EGR 270 Fundamentals of Computer Engineering Data values in 68HC11 registers Recall that registers A and B are 8 bit registers and that registers D X and Y are 16 bit registers Since the registers contain signed binary numbers note that If the MSB 0 the value is positive If the MSB 1 the value is negative and in 2 s complement form 7 A 0 7 B 0 8 Bit accumulators A and B 15 D 0 16 Bit double accumulator D 15 X 0 Index register X 15 Y 0 Index register Y 15 SP 0 Stack pointer 15 PC 0 Program Counter S X H I N Z V C Condition Code Register 1 Lecture 17 EGR 270 Fundamentals of Computer Engineering Example Determine the value stored in each register below in decimal form Register A 0 0 0 1 1 0 0 1 decimal value Register B 1 1 0 1 1 1 0 0 decimal value Register X 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 decimal value Register X 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 decimal value Example Determine the largest and smallest most negative values that can be stored in registers A and X Register Largest Value Smallest value A X 2 Lecture 17 EGR 270 Fundamentals of Computer Engineering Memory Addresses in 68HC11 registers Note that memory addresses are NOT signed binary numbers so no sign bit is used Example So if an 8 bit memory address is specified 2 hexadecimal digits as in the examples below what is the largest and smallest memory address STAA 00 memory address decimal form STAA FF memory address decimal form total amount of memory addresses with 8 bits Example So if an 16 bit memory address is specified 4 hexadecimal digits as in the examples below what is the largest and smallest memory address STAA 0000 memory address decimal form STAA FFFF memory address decimal form total amount of memory addresses with 16 bits 3 Lecture 17 EGR 270 Fundamentals of Computer Engineering 68HC11 Assembly Language Programming Examples Write a program to A Find the sum of the values in memory locations M 00 M 01 M 02 and M 03 and store the result in M 04 4 Lecture 17 EGR 270 Fundamentals of Computer Engineering 68HC11 Assembly Language Programming Examples Write a program to B Determine the smallest value in memory locations M 00 M 01 M 02 and M 03 and store it in M 04 5 Lecture 17 EGR 270 Fundamentals of Computer Engineering 68HC11 Assembly Language Programming Examples Write a program to C Write a program similar to the C program below Sum 0 for i 1 i 20 i 2 Sum Sum i 6 Lecture 17 Memory EGR 270 Fundamentals of Computer Engineering When working with microcontrollers and their limited memory it is important to be aware what memory addresses are available for 68HC11 registers Storing data Storing programs A memory map is often used to illustrate different sections of memory Different microcontrollers have different amounts of memory Note that some memory addresses are used to access RAM and others are used to access ROM RAM Random Access Memory Used for temporary storage of program data and register contents This information is lost when power is turned off to the MicroStamp11 Most MicroStamp11 s have only 256 bytes of ROM although the 64K Max MicroStamp11 is available with an additional 32kB of external RAM ROM Read Only Memory or EEPROM Electrically Erasable Programmable ROM Used to store programs i e S19 files that are downloaded This information is NOT lost when power is turned off to the MicroStamp11 The MicroStamp11 is available with 8kB 32kB or 64kB of EEPROM 7 The MicroStamp11 s to be used in lab have 32kB of EEPROM Lecture 17 EGR 270 Fundamentals of Computer Engineering Memory Map for the MicroStamp11 32k Turbo FFFF 32kB EEPROM 8000 to FFFF Used to store programs S19 files Ex Begin a program with ORG 8000 8000 7FFF 32kB External RAM 0100 to 7FFF 64k MAX version only unused in other versions 192 bytes Internal RAM 0040 to 00FF 64 bytes Internal Register Block 0000 to 003F Extra RAM for data storage Not available with our MicroStamp11 0100 00FF 0040 003F 0000 Used to store data Ex STAA 0040 Save count Used for register contents Ex LDAA 04 STAA 09 Set PD2 as an output 8 Lecture 17 EGR 270 Fundamentals of Computer Engineering 68HC11 Assembler Directives So far we have concentrated on writing assembly language using commands in the 68HC11 instruction set Additional commands called assembler directives or pseudoops are available for Specifying the memory location for the program Reserving memory for variables and assigning labels to the memory locations Specifying constants directly into memory Assembler Directives EQU ORG FCB FCC FDB BSZ RMB END 9 Lecture 17 EGR 270 Fundamentals of Computer Engineering ORG expression Directs the assembler to set an address Any code or data following an ORG will begin at the specified address Example ORG 0100 Store the following program at this location in ROM LDAA FF First line of program label EQU expression Directs the assembler to substitute the expression value where ever the label appears Example Amount EQU 10 Equate the label Amount to memory address M 10 STAA Amount Store value in memory location labeled Amount label FCB expr expr expr Form Constant Byte 8 bit constants Directs the assembler to store each value listed as an 8 bit constant in successive memory locations Example ORG 8000 10 Fibonacci FCB 0 1 1 2 3 5 8 13 Store constants beginning at M 8000 Lecture 17 EGR 270 Fundamentals of Computer Engineering label FDB expr expr expr Form Double Byte 16 bit constants Directs the assembler to store each value listed as an 16 bit constant in successive memory locations Example ORG 8000 Mask FDB 1000100110101011 Store binary value at M 8000 Data FDB 4000 6000 8000 Store 16 bit constants beginning at M 8002 label FCC String Form Character Constant Character String Directs the assembler to store the ASCII values in successive memory locations Example ORG 8000 Message FCC Hello World Store ASCII Code for H at M 8000 and remaining ASCII codes in successive bytes 11 Lecture 17 Example EGR 270 Fundamentals of Computer Engineering Write assembler directives to Store the program at memory location M 9000 Label and store two numbers NUM1 30 NUM2 50 in memory beginning at location M 8000 Label memory locations M 8002 8003 as Sum and Diff Write assembly language instructions to calculate the sum and the difference of Num1 and Num2 Draw a memory map 12 Lecture 17 EGR 270 Fundamentals of Computer Engineering label RMB expression Reserve Memory Bytes number of bytes in expression Directs the assembler to reserve the specified number of bytes and associate them with the label
View Full Document
Unlocking...