Sei sulla pagina 1di 30

ELE1301 Computer Engineering

University of Southern Queensland

ELE1301 Computer Engineering Module 11c Assembly & Machine Language Programming
Semester 1 2009 Mr Glenn Harris and Dr Wei Xiang Faculty of Engineering & Surveying University of Southern Queensland
Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

1/30

ELE1301 Computer Engineering

University of Southern Queensland

Objectives
At the completion of this module you will be able to: Describe the function of an unknown program and code it into machine code. Demonstrate the use of the index register in assembly and machine program development.

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

2/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 1
Label Field Mnemonic Field ORG num1 num2 num3 num4 num5 FCB FCB FCB FCB FCB ORG START LDX CLRA LOOP ADDA DEX BPL END JMP LOOP END $00 ,X Operand Field $0000 01 02 03 04 05 $0010 #$0004 Set the Xreg = 4 Clear Acc A Add (M) to acc A, where M = (Xreg) + 0 Decrement the Xreg for next M For M > 0000 go back to Loop Stop (endless loop) Comment Field

Describe the function of the program and code it into machine code with the program starting at $0010
Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved
3/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 1 - Solution
The flowchart
Start Load data pointer Clear accumulator Add data to accumulator decrement data pointer

Loop

Point > 0 False End

True

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

4/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 1 - Solution
Simplified memory map
0000 Data Section 0001 0002 0003 0004 0010 Program Section | xxxx END 01 02 03 04 05 START

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

5/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 1 - Solution
Table formatted
Machine Code Memory Address 0000 0001 0002 0003 0004 0010 Machine Code 01 02 03 04 05 Label Field num1 num2 num3 num4 num5 START Mnemonic Field FCB FCB FCB FCB FCB LDX CLRA LOOP ADDA DEX BPL END JMP LOOP END $00 ,X Assembly Language Operand Field 01 02 03 04 05 #$0004 Set the Xreg = 4 Clear Acc A Add (M) to acc A, where M = (Xreg) + 0 Decrement the Xreg for next M For M > 0000 go back to Loop Stop (endless loop) Comment Field

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

6/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 1 - Solution
Machine code added
Machine Code Memory Address
0000 0001 0002 0003 0004 0010 0013 0014 0016 0017 0019

Assembly Language Label Field


num1 num2 num3 num4 num5 START

Machine Code
01 02 03 04 05 CE 00 04 4F AB 00 09 2A FD 7E 00 19

Mnemonic Field
FCB FCB FCB FCB FCB LDX CLRA

Operand Field
01 02 03 04 05 #$0004

Comment Field

Set the Xreg = 4 Clear Acc A

LOOP

ADDA DEX BPL

$00 ,X

Add (M) to acc A Decrement the Xreg for next M

LOOP END

For M > 0000 go back to Loop Stop (endless loop)

END

JMP

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

7/30

ELE1301 Computer Engineering

University of Southern Queensland

Index register - Uses


Lookup tables Lists Loops counting and timing

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

8/30

ELE1301 Computer Engineering

University of Southern Queensland

Index register Lookup tables


Lookup tables are useful in the generation or translation of data that cannot be calculated due to timing constraints. Indexed addressing is well suited to keeping track of and accessing tables. Using the indexed addressing mode an effective address is formed by adding an offset to the contents of the index register.

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

9/30

ELE1301 Computer Engineering

University of Southern Queensland

Index register Lookup tables


In a lookup table sets of data are stored in such a way that the required data is selected by the offset.
Eg. Convert C to F (the offset represents C) ie. LDAA $16 ,X will return 72F for 22C, where IX = $1000
Memory Address 1014 1015 1016 1017 Table data ( F) $ 44 46 48 50 Offset $ 14 15 16 17
10/30 10/30

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

ELE1301 Computer Engineering

University of Southern Queensland

Index register Lookup tables


The advantage of this method is that no calculation of C to F is required. The disadvantage is that fractional values are not available and more memory space being taken. The programs application will dictate whether or not a lookup table should be used rather than performing the calculation.

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

11/30 11/30

ELE1301 Computer Engineering

University of Southern Queensland

Index register - Lists


A list may be considered a one-dimensional array or table. There are many ways to manipulate data in a list;
Move the list to another location Search the list Sort the list Delete items in the list

The index register can be used to track or find data within the list.

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

12/30 12/30

ELE1301 Computer Engineering

University of Southern Queensland

Index register - Loops


Counting a loop counter is used to keep track of the number of times a loop is executed. The loop counter can be a register or a memory address. The only requirement is that the we must be able to load, increment and decrement the counter. For counting loops up to 25610 an 8-bit accumulator can be used, but for counts up to 6553510 the 16-bit index register is used.

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

13/30 13/30

ELE1301 Computer Engineering

University of Southern Queensland

Index register - Loops


A loop counter can either count up or down using the increment/decrement instructions. It is more efficient to count down as the 68HC11 provides a Z flag in the status register (CC) to indicate when an increment/decrement instruction produces a zero count. The alternative is to use a compare instruction and then check the status register.

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

14/30 14/30

ELE1301 Computer Engineering

University of Southern Queensland

Index register - Loops


Timing Looping is a good way to create a time delay in a program. Time delays may be used to make a display blink or to space data transmissions. From the 68HC11 instruction set it can be seen that each instruction in each addressing mode takes a precise number of machine cycles to execute.

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

15/30 15/30

ELE1301 Computer Engineering

University of Southern Queensland

Index register - Loops


Using this information, a timing loop can be designed to produce the required time interval.
Eg. If 1 cycle = 0.5us, calculate the time interval for the following code segment LDAA DECA NOP NOP BNE #$05 2 cycles 2 cycles 2 cycles 2 cycles 4 cycles

COUNT

COUNT

The Load instruction is executed once, ie 1usec. The loop time is 0.5us x 10 cycles = 5usec for each pass, therefore executing the loop 5 times produces a time interval of 25usec. Add to this the initialisation time of 1usec, the total time is 26usec.
Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

16/30 16/30

ELE1301 Computer Engineering

University of Southern Queensland

Index register - Loops


The previous example used an 8-bit accumulator as the loop counter, so the maximum count is limited to 25610. Using the index register as the loop counter, counts up to or down from 6553510 are possible. Try the following example, using 0.5us/cycle. (ans 0.3sec)
LDX DEX NOP BNE #65535 3 3 2 4 cycles cycles cycles cycles

COUNT

COUNT

Note: The load instruction becomes less significant as the time interval increases.
Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

17/30 17/30

ELE1301 Computer Engineering

University of Southern Queensland

Index register - Loops


Nested timing loops Nesting the 0.3 second timing loop inside a counting loop of 5 will produce a time interval of about 1.5 seconds. The following code segments shows how this is done.
LDAA LDX DEX BNE DECA BNE #5 #65535 LOOP2 LOOP1

LOOP1 LOOP2

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

18/30 18/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 2
Develop a program (starting at $1000) that will provide a 0.3 second time delay, given:
Operating frequency, f = 1MHz Since machine cycle time (T) is 1/f, then T = 1usec

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

19/30 19/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 2 - Solution
Flowchart
Start

Set Counter
Loop

Counter - 1

Counter =0 True End

False

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

20/30 20/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 2 - Solution
Memory map
Reserved Section 0000 | 0FFF 1000 Program Section | | | 1008 END START Reserved for I/O registers

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

21/30 21/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 2 - Solution
Assembly language program. Counter value will need to be calculated once the number of machine cycle in the loop are known.
Machine Code Memory Address
1000

Assembly Language Label Field


START LOOP

Machine Code

Mnemonic Field
LDX DEX BNE

Operand Field
#$?

Comment Field
Counter Decrement the counter

LOOP END

For X 0000 go back to Loop Stop (endless loop)

END

JMP

LDX = 3 cycles DEX = 3 cycles BNE = 3 cycles


Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved
22/30 22/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 2 - Solution
Loop time = number of cycles in the loop x cycle time ie. 0.3 y = (6y + 3) x 1usec = 49999.510 (round off to 50000) = C35016

since the LDX instruction is only performed once it contributes very little to the delay and can be ignored.

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

23/30 23/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 2 - Solution
Machine code program

Machine Code Memory Address


1000 1003 1004 1006

Assembly Language Label Field


START LOOP

Machine Code
CE C3 50 09 26 FD 7E 10 06

Mnemonic Field
LDX DEX BNE

Operand Field
#$C350 LOOP END

Comment Field
Counter Decrement the counter For X 0000 go back to Loop Stop (endless loop)

END

JMP

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

24/30 24/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 3
Develop a program that will provide a 3 second time delay, given:
Operating frequency, f = 1MHz Since machine cycle time (T) is 1/f, then T = 1usec

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

25/30 25/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 3 - Solution
Flowchart
Start Set Counter1
Loop1

Loop 1 = 10 times Loop 2 = 0.3 sec

Set Counter2

Loop2

Counter2 - 1

Counter2 =0 True Counter1-1

False

Counter1 =0 True End


Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

False

26/30 26/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 3 - Solution
Memory map
Reserved Section 0000 | 0FFF 1000 Program Section | | | 100D END START Reserved for I/O registers

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

27/30 27/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 3 - Solution
Assembly language program. Counter value will need to be calculated once the number of machine cycle in both loops are known.
Machine Code Memory Address
1000

Assembly Language Label Field


START LOOP1 LOOP2

Machine Code

Mnemonic Field
LDAA LDX DEX BNE DECA BNE

Operand Field
#$0A #$?

Comment Field
Set counter1 to 10 Set counter2 Decrement the counter2

LOOP2

For X 0000 go back to Loop2

LOOP1 END

For A 0000 go back to Loop1 Stop (endless loop)

END

JMP

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

28/30 28/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 3 - Solution
Machine cycles
Loop1: LDAA = 2, DECA = 2, BNE = 3 Loop2 : LDX = 3, DEX = 3, BNE = 3

Loop time = cycle time x number of cycles in loops 1 and 2 ie. 3 y = [(6y + 7) x 1us] 10 = 4998610 = C34216

The value for y is a little less than the previous example due to additional instructions in the outer loop.
Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved
29/30 29/30

ELE1301 Computer Engineering

University of Southern Queensland

Problem 3 - Solution
Machine code program
Machine Code Memory Address
1000 1002 1005 1006 1008 1009 100B

Assembly Language Label Field


START LOOP1 LOOP2

Machine Code
86 0A CE C3 42 09 26 FD 4A 26 F7 7E 10 0B

Mnemonic Field
LDDA LDX DEX BNE DECA BNE

Operand Field
#$0A #$C342

Comment Field
Set counter1 to 10 Set counter2 Decrement the counter2

LOOP2

For X 0000 go back to Loop2

LOOP1 END

For A 0000 go back to Loop1 Stop (endless loop)

END

JMP

Faculty of Engineering and Surveying The University of Southern Queensland, 2009 All Rights Reserved

30/30 30/30

Potrebbero piacerti anche