New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

Class Note for ECE 4436 at UH


Class Note for ECE 4436 at UH

Marketplace > University of Houston > Class Note for ECE 4436 at UH

No professor available

Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

No professor available
Class Notes
25 ?




Popular in Course

Popular in Department

This 26 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Houston taught by a professor in Fall. Since its upload, it has received 18 views.

Similar to Course at UH


Reviews for Class Note for ECE 4436 at UH


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 02/06/15
Chap 5 The Assembler Dept of Electrical amp Computer Engineering University of Houston Fall 2008 ECE 4436 V Time Re ECE 443 6 ocata le Asembler amp Linker gt Time Source File 1 Source File 2 module1asm moduie2c Reiocatable Assembler Comp39ler Library of Object Flle 1 Object File 2 module1obj moduie2obj Otz glges Code and Data Location Information PIF39OntZE namepnn 9 Absolute File namerabs Figure 215 Linker program ECE 4436 TABLE 51 Source Code Fields Label encode Operands Comment Field Field Field Field Exampk ltwsgt ldaa ltwsgt 64 ltwsgt Initialize word counter stat3k3k Entry Initialize stack pointer ids 7SEG7END785TACK Print Hello Worldl string ldd HELLO Pass adr of the string jsr printf Jump to subroutine Spin forever spin bra spin Define the string to print HELLO DCB 39Heiio Worldl39EOS TABLE 51 Source Code Fields Label Opcode Operands Comment FEM Hdd FEM Hdd Exampkz ltwsgt ldaa ltwsgt 64 ltwsgt Initialize word counter l J Example 52 Labels Labels Examples TEST Legal label Test Different label than I FVS I TEST Legal label too Test Illegal r Duplicate label TcstData Legal TcstData Legal more readable Label Legal a label doesn39t need a colon if it starts in the rst column Labelz Illegal It does need the colon here TABLE 51 Source Code Fields Label 0pcode 0perands Comment Field Field Field Field Emampk ltwsgt ldaa ltwsgt 64 ltwsgt Initialize word counter Example 53 Operation Field Metrowerks HC12 Assembler C COPYRIGHT METROWERKS 19872003 Rel Loc Obj code Source line 1 000000 87 CLRA Legal mnemonic 2 000001 87 clra Mnemonics are not case sensitive Not legal there has to be ugt w 0 H SM at least one white space in m front of the mnemonic 6 000002 08 DCB 08 Legal assembler direcLive Example 54 Decimal Hexadecimal and Binary Constants Metzowetks HC12iAssemblet COPYRIGHT METROWERKS 19872003 c uw m w w 4 m 10 11 code Source line 000000 000002 000005 000007 000009 OOOOOC OOOOOE 8664 C1304 D2 8664 869C CE12 34 8664 86F0 Decimal Constants Op Operand Result 1daa 100 A 100 ldx 1234 X 1234 Hexadecimal Constaan ldaa S64 A 64 100 ldaa S9c A 39c i100 ldx S1234 X 1234 4660 Binary Constants Idaa 01100100 7 A 64 100 ldaa 11110000 Most Sig mask ECE 4436 Specifying ASCII Characters Example 55 Show four ways to specify the code for the ASCII code for the character C and choose the best way to load that code into the accumulatorA in a program Solution ASCIIi C or C Hexadecimal 43 Decimal 67 Binary 0100001 The best way to load accumulator A with the ASCII code for the character C is ldaa C39 ECE 4436 Assembler Expressions TABLE 54 Assembler Expressions Addition 7 Subtraction Multiplication Division produces truncated result Modulo division gtgt Shift right ltlt Shift left amp Bitwise AND I Bitwise OR Bilwise Exclusive 0R XOR l s complement 1 Logical NOT 1 or ltgt Not equal or Equal lt Less than or equal lt Less than gt Greater than or equal gt Greater than IIIGII High byte of an address LOW Low byte of an address PAGE Page byte of an address Example 57 Using an Assembler Expression Assume an assembler program with two data buffers with the start of each signi ed by the labels Datal and Data2 The two buffers are sequential in memory and the amount of data in each buffer Changes in programs for different applications Assume that somewhere in your program you want to load accumulator B with the number of bytes in the DataJ buffer Use an expression to do that Solution Metrowerks HClZ Assembler C COPYRIGHT METROWERKS 19872003 Rel Loc Obj code Source line 1 l 2 000000 C664 1dab 4Data2 e Data1 3 7 Immediate addressing 4 The assembler computes the difference between 5 7 the address of Data72 and Detail 6 7 000002 Detail DSB 100 Allocate 100 bytes 8 000066 Data 12 DSB 2100 Allocate 200 bytes ECE 4436 Comments The last field in the statement the comment starts with a semicolon Any line starting with a semicolon or asterisk in column 1 1s a Iullline comment ECE 4436 N 54 Assembler Control 55 Assembler Directives Directives appear in the opcode eld but they give directions to the assembler they are not assembled as executable instructions for the processor ECE 4436 TABLE 55 CodeWarrior HCS12 Assembler Directives Section Definition ORG SECTION OFFSET Constant Definition EQU SET Reserving or Allocating Memory Locations DS Defining Constants in Memory DCB DCW DCB RADSO Set program counter to the origin of the progmnt in an absolute assembler mode De ne a relocatable section De ne an offset section Equal symbol to an expression cannot be rede ned Assign a symbol to an expression can be rede ned De ne Storage De ne byte constant De ne word constant De ne a constant block RADSO encoded string Constants Export or Import Global Symbols ABSENTRY XDEF XREF X REFB Assembly Control ALIGN B ASE END EVEN FAIL INCLUDE LONGEVEN Repetitive Assembly Control FOR ENDFOR Listing Control CLlST LIST LLEN MLIST NOLIST NOPAGE Specify the entry point in an absolute assembly le Make a symbol public visible to some other le Import reference to an external symbol Import reference to an external symbol located on the direct page De ne alignment constraint Specify default base for constants End of assembly unit De ne tworbyte alignment constraint Genemte userde ned mm or warning messages Include text from another le De ne ourrbyte alignment constraint Repeat assembly blocks End of FOR block Include conditional assembly block Specify that all following assembly lines are in the list le De ne line length Include macro expansions Specify that all following assembly lines are not in the list le Disable pazuiatiou in the list le PAGE PLEN SPC TABS TITLE Macro Definition ENDM MACRO MEXIT Conditional Assembly ELSE EN DIF IF lFC FDEF lFEQ IFG E IFGT IFLE l FLT IFNC IFNDEF IFNE Insert page break De ne page length Insert empty or blank line De ne number of characters to insert for the lttabgt Userde ned title End of USCFdC nCtl macro Start of userde ned macro Exit from macro expansion Alternate block code included if IF statement not true End of conditional block Stan of conditional block Test if two string expressions are equal Test if a symbol is de ned Test if an expression is null Test if an expression is greater than or equal to 0 Test if an expr Ion is greater than 0 Test if an expression is less than or equal to Q Test ifan expression is less than 0 Test if two string expressions are different Test il a symbol is unde ned Test if an expression is not null Exampe 59 ORG Set Program Counter to Origin for Absolute Assembly Metrowerks HC12Assembler Metrowerks HClZeAssembler c COPYRIGHT METROWERKS 19 8 7 72 0 03 Rel Loo Obj code Source line 1 7 2 0000 C000 ROM EQU c000 Location of ROM 3 0000 0800 RAM 1300 0800 7 Location of RAM 4 0000 OAUO STACK EQU 0aOO Location of stack 5 7 6 ORG ROM Set program counter 397 i to ROM tor code 8 7 The following code is located at memory 9 address ROM 10 OOCOOO CFOA 00 ids STACK Initialize SP 11 00C003 B608 00 ldaa Data1 Load from memory 12 address RAM 13 14 ORG RAM Set program counter 15 to RAM for the data 16 000800 Data1 DSB 20 7 Set aside S20 bytes Example 510 SECTION Metrowerks HClZ Assembler C COPYRIGHT METROWERKS 19872003 Rel Loc Obj code Source line 1 I 2 RAM SECTION De ne the section that 3 will go into RAM for Starts at zero variable 4 J storage 5 000000 Buf1DS 10 6 7 ROM SEC l lON De ne the section that goes 8 Starts at zero into ROM for the code 9 1 entry 10 000000 F56xx XX ldaa Bufi l ll 000003 7Axx xx staa Bufll Example 512 EQU Equate Symbol Metrowerks HClZeAssembler c Rel Loc Obj 1 2 0000 3 4 5 6 0000 7 8 0000 9 10 11 0000 12 13 111 0000 15 16 17 18 000000 0130A 19 000002 20 000008 861E 21 OOOOOA 8401 22 00000C C40F COPYRIGHT METROWERKS 19872003 code Source line UDUA CRLF EQU SODOA For each occurrence of CRLF the assembler will 7 substitute the value SODOA 0006 COUNT EQU 6 7 Loop counters often need to be initialized 0018 COUNle EQU COUNT S The assembler can evaluate an expression to provide a va1ue of 30 For COUNTl OOOF LSMASK EQU 0F A mask that picks off the least signi cant nibble in a byte 000539 lsimaskd lQU 00001111 A binary mask equate is more readable and informative than one given in hexadecimal Here are some code examples using the EQUs DC W CRLF DS B COUNT ldaa RCOUNTl anda 1smask andb LSiMASK ECE 4436 SET Set a Symbol to a Value SET is similar to EQU except the value set is temporary and can be rede ned later in the program by another SET SET is useful in include les that each wish to de ne the same symbol avoiding the error message that an EQU would generate ltlabelzgt SET ltExpressiongt Comment Q SET OD ASCII real Example 515 Define Constant Metrowerks HClZ Assembler m Rel UUUUUU 000001 000003 000004 000006 000008 00000A 12 13 000003 14 15 16 17 18 19 OOOOOC 000010 1n Obj 64 0064 23 1234 BEEF BEEF 65 COPYRIGHT METROWERKS 19872003 Code Source line De ne decimal Constants De ne a byte DCW 100 De ne a word Hexadecimal Constants DCB 23 CW 1234 DCW bee DCW EEEF Uppercase same as lowercase Binary Constants DC 0101 Valid 5 is default size DCB 0101 Invalid missing i Assembler thinks this is 7 decimal 101 Initialize four memory locations with the data 01 02 10 and Sff EQU 255 EQU e128 Data DCB 01 02 10 MAX MID DUFF MAX FF80 MID 0102 10FF 80 A pimv x qihmi H u 05F A Examplie 5 16 ASCII Strings Metrowerks HC127Assemb1er C COPYRIGHT METROWERKS 19872003 Rel Loc Obj Code Source line 1 2 000000 4161 62 DCB A a b 3 000003 5468 6973 DCB quotThis is a stringquot 00000 2069 320 000008 6120 7374 OOOOOE 7269 61367 000013 2E 4 0000 GOOD CR EQU 50d ASCII code for carriage reLurn 5 0000 000A LF EQU 05 ASCII code for line feed 6 000014 4865 7265 Msg DCB quotHere is a string withquotCRLF 000018 2069 7320 00001C 6120 7374 000020 7269 6E67 000024 2077 6974 000028 680D 0A 7 0000213 6361 7272 DCB carriage return and line feed ECE 4436 Example 513 DS Define Storage Metrowerks HCl2iAssembler C COPYRIGHT METROWERKS 19872003 Allocates 10 bytes BUFFERl DSB 2COUNT3 Allocates S20 bytes Rel Loo Obj code Source line 1 I 2 0000 0010 COUNT73 EQU 10 3 000000 BUFFER DS COUN L 3 4 000010 5 000030 BUFFER2 DSW COUNT3 Allocates 10 words Example 514 Show how to use the DS directive lo reserve 10 bytes for data Initialize each byte to zero in a small program segmenL Solution Mecrowerks HClZ Assembler C COPYRIGHT METROWERKS 19872003 Rel Loc Obj code Source line 1 I 2 0000 000A NUMBER EQU lO Number of bytes allocated 17 ORG RAM Locate the data area 18 000900 BUF DS NUMBER Allocate the data 6 Fee ECE 4436 Extrnl 4 m l XDEF External Symbol De nition XDEF allows you to de ne a label in the current module to be made Visible public global Via the Linker in other modules XDEFsize ltlabelgtlabel Exports a XDE F Ent ry symbol XREF External Symbol Reference XREF declares for the current module that a variable used in this module is actually de ned in another module The Linker will nd it Imports a XREFsize ltlabelgtlabel Symbol XREF printf XREF SEGENDSSTACK ECE 4436 Examle roram to rint quotHello Worldquot Source File helloasm Author F M Cady Created 902 kkkkk Constant equates EOS EQU 0 End of string Linker symbols ex ort 39Entr 39 s mbol XDEF Entry Subroutine to printf XREF printf Stack pointer XREF SEGENDSSTACK Entry Initialize stack pointer lols SEGENDSSTACK Print Hello World string ldd HELLO Pass adr of the string jsr printf Jump to subroutine Example 517 INCLUDE The source le is includeasm INCLUDE quotboj lerplate incquot 139 other code follows and the assembler list le shows the le with the include le Metrowerks HClZ Assembler C COPYRIGHT METROWERKS 198742003 Abs Rel Lyoc Obj code Source line 1 l includeasm 2 2 I 3 3 INCLUDE quotboilerplateincquot 5 21 boilerplateinc 6 3i This le contains a variety of commonly 7 41 used equates 8 5i 0000 GOOD CR EQU 50d ASClI for carriage return 399 61 0000 000A LF EQU 50a Line feed 10 7i 0000 0000 NULL EQU 0 Null terminator ll 8i End of include le 12 4 other code follows 13 b iii 57 Remaining Questions ECE 4436 N 58 Conclusion and Chapter Summary Points


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Allison Fischer University of Alabama

"I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over $600 per month. I LOVE StudySoup!"

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."


"Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.