230 likes | 401 Views
ECE 265 – Lecture 11. Editing and the Assembler (updated 11/11/10). 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
E N D
ECE265 ECE 265 – Lecture 11 Editing and the Assembler (updated 11/11/10)
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 4.11 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. ECE265
What is output from the assembler • Input is your assembler language program • The output will look something like this ECE265
And a machine code listing ECE265
Another example ECE265
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. ECE265
Previous example • The code • ORG $0010 • unkwn FCB 47 set unknown value • guess RMB 1 location for guess var • incr RMB 1 location for increment var • ORG $C000 • LDAA #50 • STAA guess • LSRA divide by 2 • STAA incr first guess is 50 • LDAB incr • LSRB set to 25 ECE265
Previous ex continued • tol CMPA unknwn • BEQ done • BLT low • * guess is too high • SBA subtract increment • incadj LSRB incr = incr/2 • BCC ceilgd • INCB carry was 1 so make ceil • ceilgd BRA tol • low ABA add increment • BRA incadj • done STAA guess done ECE265
Hand assembly • Assembler directives • ORG $0010 • unknwn FCB 47 set unknown value • guess RMB 1 location for guess var • incr RMB 1 location for increment var • Assembler output • LabelLOCContents($) • unkwn $0010 $2F • guess $0011 • incr $0012 ECE265
Hand assembly continued • The lines hand assemble • ORG $C000 • LDAA #50 • addr contents • $C000 86 32 • $32 is 0011 0010 • and hexidecimal • for 50 (32+16+2) ECE265
The next instruction • STAA guess • $C002 $97 11 • As address of • Guess is $0011 ECE265
And then • LSRA • $C004 44 • STAA incr $C005 97 12 ECE265
And then • LDAB incr • $C007 D6 12 • LSRB • $C009 54 ECE265
And then • tol CMPA unkwn • $C00A 91 10 • As unkwn is at memory • Location $0010 • tol will have value of • $C00A ECE265
And then • BEQ done • BLT low • $C00C 27 rrdone • $C00E 2d rrlow • Where the relative address will be filled in after the first pass. ECE265
And then • SBA • $C010 10 • incadj LSRB • $C011 54 ECE265
And then • BCC ceilgd • $C012 24 rrjump • INCB • $C014 5C • ceilgd BRA tol • $C015 20 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. 0001 0111 – 0000 1010 = 0000 1101 • Or back_to_tol gets $F3 WHY? ECE265
And finally • low ABA • $C017 18 • And low has an address of $C017 • so rrlow gets 9 • BRA incadj • $C018 20 to_incadj • incadj was at address $C011 so this is a -9 • or to_incadj getting $F7 • done STAA guess • $C01A 97 10 ECE265
The full code • ORG $0010 • Loc contents comment • ORG $0010 • $0010 47 unkwn FCB 47 • $0011 00 guess RMB 1 • $0012 00 incr RMB 1 • ORG $C000 • $C000 86 64 LDA #100 • $C002 97 11 STAA guess • $C004 44 LSRA • $C005 97 12 STAA incr • $C007 D6 12 LDAB incr • $C009 54 LSRB • $C00A 91 10 tol CMPA unkwn • $C00C 27 0E BEQ done • $C00F 2D 09 BLT low • $C010 10 SBA • $C011 54 incadj LSRB • $C012 24 01 BCC ceilgd • $C014 5C INCB • $C015 20 F3 ceilgd BRA tol • $C017 18 low ABA • $C018 20 F7 BRA incadj • $C01A 97 10 done STAA guess • Symbol table • unkwn $0010 tol $C00A low $C017 • guess $0011 incadj $C011 done $C01A • incr $0012 ceilgd $C015 ECE265
Lecture summary • Have looked at hand assembly • a very useful skill ECE265
From the assembler • Copy of the window ECE265
Assignment • 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. ECE265