ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/ ECE265
Lecture Overview Editing and Assembler So far have covered the assembler language instructions and translating a program to assembler Now Creating the assembler code file What goes on during the execution of the assembler REF: Chapter 4.10 and /15/ ECE265
Assembler language files Translated HLL to assembler. Edit the assembler language program into an editor. This is sometimes called a source file What is done with the source file? It is input as a data file to a program called and assembler. Most times you simply use a simple text editor and set up the various fields at tabs. The file is save as name.asm typically. 12/15/2015ECE265 3
What is output from the assembler Input is your assembler language program The output will look something like this 12/15/2015ECE265 4
And a machine code listing 12/15/2015ECE265 5
Another example 12/15/2015ECE265 6
Hand assembly Knowing how to hand assemble assembler code is useful knowledge. This is the same work the assembler does. What value does knowing this help a computer engineer? It goes to knowledge base and a complete understanding of a processors (microprocessor or microcontroller) architecture. It is essential to being able to design and implement front line embedded systems requiring very accurate timing. 12/15/2015ECE265 7
Previous example The code ORG $0010 unkwn FCB47 set unknown value guessRMB 1 location for guess var incrRMB1 location for increment var ORG $C000 LDAA #50 STAA guess LSRAdivide by 2 STAA incr first guess is 50 LDAB incr LSRB set to 25 12/15/2015ECE265 8
Previous ex continued tolCMPA unknwn BEQ done BLT low * guess is too high SBAsubtract increment incadjLSRBincr = incr/2 BCC ceilgd INCBcarry was 1 so make ceil ceilgdBRA tol lowABAadd increment BRA incadj doneSTAA guessdone 12/15/2015ECE265 9
Hand assembly Assembler directives ORG $0010 unknwnFCB47 set unknown value guessRMB 1 location for guess var incrRMB1 location for increment var Assembler output Label LOC Contents($) unkwn $0010 $2F guess $0011 incr $ /15/2015ECE265 10
Hand assembly continued The lines hand assemble ORG $C000 LDAA #50 addr contents $C $32 is and hexidecimal for 50 ( ) 12/15/2015ECE265 11
The next instruction STAA guess $C002 $97 11 As address of Guess is $ /15/2015ECE265 12
And then LSRA $C STAA incr $C /15/2015ECE265 13
And then LDAB incr $C007 D6 12 LSRB $C /15/2015ECE265 14
And then tol CMPA unkwn $C00A As unkwn is at memory Location $0010 tol will have value of $C00A 12/15/2015ECE265 15
And then BEQ done BLT low $C00C 27 rrdone $C00E 2d rrlow Where the relative address will be filled in after the first pass. 12/15/2015ECE265 16
And then SBA $C incadjLSRB $C /15/2015ECE265 17
And then BCC ceilgd $C rrjump INCB $C014 5C ceilgdBRA tol $C back_to_tol ceilgd had value $C015 and at time of BCC execution, the PC will have value of $C014 so rrjump gets value of $01 back to tol will need a negative offset. The PC for calculation back to location $C00A from location $C017 is a negative 13 bytes – = Or back_to_tol gets $F3 WHY? 12/15/2015ECE265 18
And finally lowABA $C And low has an address of $C017 so rrlow gets 9 BRA incadj $C to_incadj incadj was at address $C011 so this is a -9 or to_incadj getting $F7 doneSTAA guess $C01A /15/2015ECE265 19
The full code ORG $0010 Loc contents comment ORG $0010 $ unkwn FCB 47 $ guess RMB 1 $ incr RMB 1 ORG $C000 $C LDA #100 $C STAA guess $C LSRA $C STAA incr $C007 D6 12 LDAB incr $C LSRB $C00A tol CMPA unkwn $C00C 27 0E BEQ done 12/15/2015ECE $C00F 2D 09 BLT low $C SBA $C incadj LSRB $C BCC ceilgd $C014 5C INCB $C F3 ceilgd BRA tol $C low ABA $C F7 BRA incadj $C01A done STAA guess Symbol table unkwn $0010 tol $C00A low $C017 guess $0011 incadj $C011 done $C01A incr $0012 ceilgd $C015
Lecture summary 12/15/2015ECE Have looked at hand assembly a very useful skill
From the assembler Copy of the window 12/15/2015ECE265 22
Assignment 12/15/2015ECE Get to a THR simulator (will be downloadable from Carmen) Enter the program we just hand assembled and confirm the hand coding. (CODE IS ON slide 8 and 9) NOTE: page 0 has RAM and page E has ROM for you code. Use the table on page 27 for address of I/O. See example code on webpage. Submit a 1/3 to full page writeup on if the code agrees or not, and your level of understanding of what an assembler does. Also capture the simulator window and turn in a copy of the simulator window after you have done the assemble.