ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

23
ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 06/21/22 1 ECE265

Transcript of ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Page 1: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

ECE 265 – LECTURE 11

Editing and the Assembler

(updated 11/11/10)

04/22/23

1ECE265

Page 2: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

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

04/22/23

2

ECE265

Page 3: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

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.

04/22/23ECE265

3

Page 4: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

What is output from the assembler

Input is your assembler language program

The output will look something like this

04/22/23ECE265

4

Page 5: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

And a machine code listing

04/22/23ECE265

5

Page 6: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

Another example

04/22/23ECE265

6

Page 7: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

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.

04/22/23ECE265

7

Page 8: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

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

04/22/23ECE265

8

Page 9: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

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

04/22/23ECE265

9

Page 10: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

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 Label LOC Contents($) unkwn $0010 $2F guess $0011 incr $0012

04/22/23ECE265

10

Page 11: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

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)

04/22/23ECE265

11

Page 12: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

The next instruction

STAA guess

$C002 $97 11

As address of Guess is $0011

04/22/23ECE265

12

Page 13: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

And then

LSRA $C004 44 STAA incr

$C005 97 12

04/22/23ECE265

13

Page 14: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

And then

LDAB incr $C007 D6 12 LSRB $C009 54

04/22/23ECE265

14

Page 15: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

And then

tol CMPA unkwn

$C00A 91 10

As unkwn is at memory Location $0010

tol will have value of $C00A

04/22/23ECE265

15

Page 16: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

And then

BEQ done BLT low

$C00C 27 rrdone $C00E 2d rrlow

Where the relative address will be filled in after the first pass.

04/22/23ECE265

16

Page 17: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

And then

SBA $C010 10 incadjLSRB $C011 54

04/22/23ECE265

17

Page 18: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

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?

04/22/23ECE265

18

Page 19: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

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

04/22/23ECE265

19

Page 20: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

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

04/22/23ECE265

20

$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

Page 21: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

Lecture summary

04/22/23ECE265

21

Have looked at hand assembly a very useful skill

Page 22: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

From the assembler

Copy of the window

04/22/23ECE265

22

Page 23: ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/2015 1 ECE265.

Joanne E. DeGroat, OSU

Assignment

04/22/23ECE265

23

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.