DOC PREVIEW
NMT EE 308 - EE 308 Exam 1

This preview shows page 1-2-3-4 out of 12 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 2009Exam 1Feb. 23, 25, 27?• You w ill be able to use all of the Motorola data manuals on the exam.• No calculators will be allowed for the exam.• Numbers– Decimal to Hex (signed and unsigned)– Hex to Decimal (signed and unsigned)– Binary to Hex– Hex to Binary– Addition and subtraction of fixed-length hex numbers– Overflow, Carry, Zero, Negative bits of CCR• Programming Model– Internal registers – A, B, (D = AB), X, Y, SP, PC, CCR• Addressing M odes and Effective Addresses– INH, IMM, DIR, EXT, REL, IDX (Not Indexed Indirect)– How to determine effective address• Instructions– What they do - Core Users Guide– What machine code is generated– How many cycles to execute– Effe ct on CCR– Branch instructions – which to use with signed and which with unsigned• Machine Code– Reverse Assembly• Stack and Stack Pointer– What happens to stack and SP for instructions (e.g., PSHX, JSR)– How the SP is used in getting to and leaving subroutines• Asse mbly Language– Be able to read and write simple assembly language program– Know basic assembler directives – e.g., equ, dc.b, ds.w– Flow charts1EE 308 Spring 2009Programming the HC12 in C• A c omparison of some assembly language and C constructsAssembly | C------------------------------|------------------------------------; Use a name instead of a num | /* Use a name instead of a num */COUNT: EQU 5 | #define COUNT 5;-----------------------------| /*-----------------------------*/;start a program | /* To start a program */org $2000 | main()lds #0x2000 | {| };-----------------------------| /*-----------------------------*/• Note that in C, the starting location of the program is defined when you compile theprogram, not in the program itself.• Note that C always uses the stack, so C automatically loads the stack pointer for you.Assembly | C------------------------------|------------------------------------;allocate two bytes for | /* Allocate two bytes for;a signed number | * a signed number */|org $1000 |i: ds.w 1 | int i;j: dc.w $1A00 | int j = 0x1a00;;-----------------------------| /*-----------------------------*/;allocate two bytes for | /* Allocate two bytes for;an unsigned number | * an unsigned number */i: ds.w 1 | unsigned int i;j dc.w $1A00 | unsigned int j = 0x1a00;;-----------------------------| /*-----------------------------*/;allocate one byte for | /* Allocate one byte for;an signed number | * an signed number */|i: ds.b 1 | signed char i;j: dc.b $1F | signed char j = 0x1f;2EE 308 Spring 2009Assembly | C;-----------------------------| /*-----------------------------*/;Get a value from an address | /* Get a value from an address */; Put contents of address | /* Put contents of address */; $E000 into variable i | /* 0xE000 into variable i */|i: ds.b 1 | unsigned char i;|ldaa $E000 | i = * (unsigned char *) 0xE000;staa i || /*-----------------------------*/| /* Use a variable as a pointer| (address) */|| unsigned char *ptr, i;|| ptr = (unsigned char *) 0xE000;| i = *ptr;| *ptr = 0x55;;-----------------------------| /*-----------------------------*/• In C, the construct *(num) says to treat num as an address, and to work with thecontents of that address.• Be cause C does not know how many bytes from that address you want to work with,you need to tell C how many bytes you want to work with. You also have to tell Cwhether you want to treat the data as signed or unsigned.– i = * (unsigned char *) 0xE000; tells C to take one byte from address 0xE000,treat it as unsigned, and store that value in variable i.– j = * (int *) 0xE000; tells C to take two bytes from address 0xE000, treat itas signed, and store that value in variable j.– * (char *) 0xE000 = 0xaa; tells C to write the number 0xaa to a single byteat addess 0xE000.– * (int *) 0xE000 = 0xaa; tells C to write the number 0x00aa to two bytesstarting at addess 0xE000.3EE 308 Spring 2009Assembly | C;-----------------------------| /*-----------------------------*/;To call a subroutine | /* To call a function */ldaa i | sqrt(i);jsr sqrt |;-----------------------------| /*-----------------------------*/;To return from a subroutine | /* To return from a function */ldaa j | return j;rts |;-----------------------------| /*-----------------------------*/;Flow control | /* Flow control */blo | if (i < j)blt | if (i < j)|bhs | if (i >= j)bge | if (i >= j);-----------------------------| /*-----------------------------*/|• Here is a simple program written in C and assembly. It simply divides 16 by 2. It doesthe division in a function.ASSEMBLY | C---------------------------|---------------------|org $1000 | signed char i;i: ds.b 1 ||| signed char div(signed char j);org $1000 | main()lds #$2000 | {ldaa #16 | i = div(16);jsr div | }staa i |swi ||div: asra | signed char div(signed char j)rts | {| return j >> 1;| }4EE 308 Spring 2009A simple C program and how to compile itHere is a simple C program#define COUNT 5unsigned int i;main(){i = COUNT;}Details of compiling a program are discussed in detail in the text in Section 5.10. Hereis an outline of the details:1. Open the Embedded GNU (EGNU) IDE.2. From the File menu, select the New Source File option. Type in your C program.Then from the File menu, select the Save unit as submenu, and save your file withan appropriate name and in an appropriate directory.3. From the File menu, select the New Project option. Give the project an appropriatename and an appropriate directory. (Note: the project base name must be differentfrom the C file names.) When the Project Options popup dialog appears, click thedown arrow below Hardware Profile, and select Dragon12. Click the Edit Profilebutton, and make sure the following are set:• ioports from 0000, length 400• eeprom from 400, length c00• data from 1000, length 1000• text from 2000, length 2000• stack at 2000Then click the OK button.4. From the Project menu, select the Add to project option, and, in the pop-up dialogbox, select the C file you entered in Step 2.5. From the Build menu, select the Make option. Under the Compiler window at thebottom of the screen, you will hopefully see the message No errors or warnings. Ifnot, you will need to fix the errors.6. If all went well, you should be able to download the compiled file into the 9S12.5EE 308 Spring 2009If the name of your project is Project1.prj, the compiler will generate a file Project1.dmp.Here is some of the output from Project1.dmp. There are a couple of


View Full Document

NMT EE 308 - EE 308 Exam 1

Documents in this Course
Load more
Download EE 308 Exam 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view EE 308 Exam 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view EE 308 Exam 1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?