ME 4447/6405 Microprocessor Control of Manufacturing Systems and

Slides:



Advertisements
Similar presentations
Lecture 5: MIPS Instruction Set
Advertisements

Programming 68HC11.
Assembler Programming Chapter 6. EEL-4746 Best Practices.
H. Huang Transparency No.1-1 The 68HC11 Microcontroller Chapter 1: Introduction to 68HC11 The 68HC11 Microcontroller.
Chapter 3 Assembly Language: Part 1. Machine language program (in hex notation) from Chapter 2.
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
8051 ASSEMBLY LANGUAGE PROGRAMMING
ECE 265 – LECTURE 9 PROGRAM DESIGN 8/12/ ECE265.
© 2010 Kettering University, All rights reserved..
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
Assembly Language Programming for the MC68HC11. Assembly language programming  Recall the 4 design levels for software development: – Application – High.
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 7: Assembly Language.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
ME4447/6405 The George W. Woodruff School of Mechanical Engineering ME4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Objectives Implement pointers using indexed addressing modes Use pointers to access arrays, strings, structures, tables, and matrices Present finite-state.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
6-1 EE 319K Introduction to Microcontrollers Lecture 6: Indexed Addressing Mode and Variants, Functional Debugging, Arrays, Strings.
ME4447/6405 The George W. Woodruff School of Mechanical Engineering ME4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics.
3-1 EE 319K Introduction to Microcontrollers Lecture 3: Addressing modes, Memory Operations, Subroutines, I/O, Logical/Shift Operations.
1 Segments and Pseudo Operations Program Development.
Assembly Language ELEC 330 Digital Systems Engineering Dr. Ron Hayne.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
1 ECE 372 – Microcontroller Design Assembly Programming HCS12 Assembly Programming Addressing Modes Stack Operations Subroutines.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Ch.2 Intro. To Assembly Language Programming
ECE Lecture 21 Typical Assembly Language Program Bugs.
Ch.2 Intro. To Assembly Language Programming From Introduction to Embedded Systems: Interfacing to the Freescale 9s12 by Valvano, published by CENGAGE.
Advanced Assembly Language Programming
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
EE345 Chapter 2 Lecture 3 April Instruction and addressing modes 1.Extended Addressing 2.Direct Addressing 3.Inherent Addressing 4.Immediate Addressing.
PROGRAMMING THE BASIC COMPUTER
ECE 3430 – Intro to Microcomputer Systems
Addressing Modes in Microprocessors
MIPS Instruction Set Advantages
ECE 3430 – Intro to Microcomputer Systems
Assembly Language (continue)
ECE 3430 – Intro to Microcomputer Systems
Learning Outcome #1 Architecture and Programming Model
Assembly Language Programming of 8085
ECE 3430 – Intro to Microcomputer Systems
PROGRAMMING THE BASIC COMPUTER
ECE 3430 – Intro to Microcomputer Systems
Lecture 4: MIPS Instruction Set
ECE 3430 – Intro to Microcomputer Systems
Wed. Sept 6 Announcements
“Assembly Table Lookup”
Computer Science 210 Computer Organization
Branching and Looping Lecture L3.2.
ME4447/6405 Microprocessor Control of Manufacturing Systems and
Computer Science 210 Computer Organization
Lecture 4: MIPS Instruction Set
ECE 3430 – Intro to Microcomputer Systems
Chap. 6 Programming the Basic Computer
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
A Simple Two-Pass Assembler
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
8051 ASSEMBLY LANGUAGE PROGRAMMING
Chapter 6 Programming the basic computer
Indexing Through Memory
The .ASCII and .END Assembler Input ;Stan Warford ;January 13, 2005
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Accum A: Index X: CCR Bit Z: $0100 $0101 $0102 $0103 $0104 $0105
ECE511: Digital System & Microprocessor
Part I Data Representation and 8086 Microprocessors
Presentation transcript:

ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics Instructor: Professor Charles Ume Lecture #11

Homework Set #1 Solution 1. Write an assembly language program to clear the usable internal RAM in the MC9S12C32 [$0800 to $0DFF] Solution: Clear Locations $0800 - $0DFF. ORG $1000 LDX #$0800 LOOP CLR $00,X INX CPX #$0E00 BNE LOOP SWI END (NOTE: You should hand-assemble this program.)

Homework Set #1 Solution 2. Write a program to add even/odd numbers located in addresses $0000 through $00FE. Solution: (for adding odd numbers) ORG $1000 LDY #$0000 1000 CD 0000 LDX #$0000 1003 CE 0000 IND LDAA #$FF 1006 86 FF LDAB $00,X 1008 E6 00 BITB #$01 100A C5 01 BEQ EVEN 100C 27 02 ABY 100E 19 ED EVEN INX 1010 08 STX $2000 1011 7E 2000 EORA $2001 1014 B8 2001 BNE IND 1017 26 ED SWI 1019 3F END 0000 0011 0000 0001 OR DECA 4A If you use this, then IND should be moved down to the next line 1st Time $2001: 0000 0001 Acc A: 1111 1111 1111 1110

Homework Set #1 Solution 2. Write a program to add even/odd numbers located in addresses $0800 through $0900. Solution: (for adding odd numbers) ORG $1000 LDY #$0000 1000 CD 0000 LDX #$0800 1003 CE 0800 IND LDAB $00,X 1006 E6 00 BITB #$01 1008 C5 01 BEQ EVEN 100A 27 02 ABY 100C 19 ED EVEN INX 100E 08 CPX #$0901 100F 8E 0901 BNE IND 1012 26 ED SWI 1014 3F END

Homework Set #2 Solution Write an assembly language program to find the largest signed number in a list of numbers stored in address $0020 thru $0029, and store it in $2000. Repeat for unsigned number. FIRST EQU $0020 LAST EQU $002A ANSWR EQU $2000 ORG $1000 LDX #FIRST LDAA FIRST STAA ANSWR INX Goes with DECB. If DECB is removed, then LDAB #$0A LDAB must be removed NUB LDAA $00,X CMPA ANSWR (A - ANSWR) BLE NEXT; (signed)* *(Branches if 2's complement number in register A is less than or OR equal to the 2's complement number represented by ANSWR) BLS NEXT; (unsigned)** **(Branch if lower or same, i.e, Branch if register A was lower or same as ANSWR) STAA ANSWR NEXT INX CPX #LAST OR DECB BNE NUB SWI END

Homework Set #2 Solution Continued Signed Example: #$3F (positive) #$F4 (negative) Convert Numbers to Decimal: #$F4 = %11110100 1's Comp #$0B = %00001011 2's Comp #$0C = %00001100 #$F4 = -1210 #$3F = %00111111 #$3F = 6310 #$3F is larger than #$F4 since 6310 is larger than -1210 Un-Signed Example: #$3F (positive) #$F4 (positive) Convert Numbers to Decimal: #$F4 = %11110100 #$F4 = 24410 #$3F = %00111111 #$3F = 6310 #$F4 is larger than #$3F since 24410 is larger than 6310

Homework Set #3 Solution 1. Write a subroutine to save the first 5 odd (8-bit) numbers pointed to by the x-register (passed in) onto the stack. Solution: SUB1 LDAA #$05 PULY NEXT BRSET $00,X #$01 ODD INX BRA NEXT ODD LDAB $00,X PSHB DECA BNE NEXT PSHY RTS Note: For subroutine to execute in main program, a BSR or JSR command must be used in main program.

Homework Set #3 solution 2. Write a program to output a square wave thru port S pin The output can be observed on the scope, and the period T of the wave should be measured. More than one period wave should be generated. The machine cycle time of the MC9S12C32 should be estimated. Draw the square wave.

Homework Solution Cont’d ORG $2000 FCB $XX FCB $04 ORG $1000 LDAA #$04 STAA $024A LDAB #$04 CYCLE LDAA $2001 3 STAA $0248 3 EORA #$04 1 STAA $2001 3 LDAA $2000 3 NEXT DECA 1 BNE NEXT 3/1 DECB 1 BEQ EXIT 3/1 JMP CYCLE 3 EXIT SWI END Address Opcode Postbyte Operand 1000 86 04 1002 7A 024A 1005 C6 04 1007 B6 2001 100A 7A 0248 100D 88 04 100F 7A 2001 1012 B6 2000 1015 43 1016 26 FD 1018 53 1019 27 03 101B 06 1007 101E 3F Configures PS2 as output. Helps us to output two periods. Outputs signal from PS2 Switch $2001(toggle) Delay (Note: BNE and BEQ take 3 machine cycles to execute if the branch is taken and one machine cycle if it is not taken) T/2=Machine Cycle Time*[3+3+1+3+3+COUNT*(1)+(COUNT-1)*3+1+1+3] (Note: Count = #$XX)

ASCII Character Codes

Examples: ASCII Character Codes ASCII – American Standard Code for Information Interchange ASCII assigns a hexadecimal ‘code’ to individual characters Examples: Character ASCII ‘A $41 ‘E $45 ‘e $65 (Note: Different codes for lower and upper case) ‘1 $31 BS $08 (Note: BS is Backspace. ) A microcontroller must send these codes to a display terminal in order for the terminal to display these characters.

ASCII Character Codes (continued) Hex to ASCII Conversion table from Programming Reference Guide Page 58

An array of characters is called a string ASCII Character Codes An array of characters is called a string Example: character array String ASCII Representation ‘H ‘e ‘l ‘l ‘o “Hello” $48 $65 $6C $6C $6F (Note: Character ASCII ‘H $48 ‘e $65 ‘l $6C ‘o $6F )

Assembly Directives

Assembly Directive Types Assembly Control ORG, END Symbol Definition EQU Data Definition/Storage Allocation FCC, FCB, FDB, RMB, ZMB, BSZ, FILL Listing Control PAGE, OPT

Assembly Control

ORG and END ORG : Store translated machine language instructions in sequence starting at given address for any mnemonic instructions that follow END: Stop translating mnemonics instructions until another ORG is encountered (Note: These were already discussed in Lecture 7)

Symbol Definition

EQU EQU lets you refer to a number or an address as a variable name. Example: VALA EQU $10 *LABEL VALA USED TO REFER TO $10 ORG $1000 LDAA #VALA *LOAD HEX NUMBER $10 IN ACCUMULATOR A LDAB VALA *LOAD CONTENT OF MEMORY LOCATION $10 *IN ACC. B SWI END Same As: LDAA #$10 *LOAD HEX NUMBER $10 IN ACCUMULATOR A LDAB $10 *LOAD CONTENT OF MEMORY *LOCATION $10 IN ACC. B

Data Definition/Storage Allocation

FCC FCC – Form Constant Character string FCC stores ASCII characters into consecutive bytes of memory. Any printable ASCII characters can be contained in the string. String is specified between two identical delimiters, which can be any printable ASCII character. First non-blank character after the string is used as a delimiter.

FCC Cont’d Result Example: ORG $0400 FCC “12345” Address Prebyte Opcode Operand $0400 31 32 $0401 33 $0402 $0403 34 $0404 35

FCB FCB – Form Constant Byte FCB has one or more operands. Value of each operand is truncated to eight bits, and is stored in single byte of object program. Operand may be a numeric constant, character constant, a symbol or an expression. Multiple operands are separated by commas, and are stored in successive memory bytes.

FCB Cont’d Result Example: VALA EQU $10 ORG $0400 FCB $34,’A, $28AC, $0A ,VALA Address Prebyte Opcode Operand $0400 34 41 $0401 AC $0402 $0403 0A $0404 10

FDB FDB – Form Constant Double Byte FDB stores a double (two byte) word. May have one or more operands separated by commas. Operand may be a numeric constant, a character constant, a symbol, or an expression.

Note: ASCII value for & is $26 FDB Cont’d Result Example: ORG $0400 FDB $1234,’&,’G Address Prebyte Opcode Operand $0400 12 $0401 34 00 $0402 $0403 26 $0404 00 $0405 47 Note: ASCII value for & is $26 ASCII value for G is $47

RMB Result RMB – Reserve Memory Byte RMB saves a place in memory for a number. Example: ORG $0400 XVAR RMB 2 *TWO MEMORY *LOCATIONS $0400 *and $0401 ARE *RESERVED FOR XVAR ORG $1000 LDD #$FFAA STD XVAR SWI END Result Address Prebyte Opcode Operand $0400 FF AA $0401

Question a student asked: What happens if you change the previous example to "XVAR RMB 3" instead of "XVAR RMB 2" ? What happens to the 3rd reserved byte when a 2 byte number is stored in XVAR? Answer: Remains unchanged Modified Program: ORG $0400 XVAR RMB 3 ORG $1000 LDD #$FFAA STD XVAR SWI END

ZMB, BSZ ZMB – Zero Memory Byte and BSZ – Block Storage of Zero These directives fill a given number of memory locations with zero. Causes assembler to allocate a block of memory bytes, and each memory byte is assigned a value of zero. Both directives do the same thing. Number of bytes allocated is given in the operand field. Result Example: ORG $0400 ZMB #$02 BSZ #$02 Address Prebyte Opcode Operand $00 00 $01 00 $02 00 $03 00

FILL Fill given number of memory locations with any number. (Note: Fill uses one byte. If two bytes are specified, then it will truncate it and use LS Byte.) Example: ORG $0400 FILL #$FF, #$02 Result Address Prebyte Opcode Operand $00 FF FF $01

Question a student asked: What happens when the previous example is changed to "FILL #$9ABC, #$02" instead of "FILL #$FF,#$02"? What happens if you fill memory with a 2 byte number? Answer: FILL will just use the LS Byte Modified Example: ORG $0400 FILL #$9ABC,#$02 END (Note: There is no ”go 1000” on the screen since these are just assembly directives and not a program)

Listing Control

PAGE PAGE The PAGE directive causes a page break in the list file. If no source listing is being produced, the PAGE directive will have no effect. The directive is not printed on the source listing.

OPT OPT Allows for various options in assembly of a program, including generating a listing and counting instruction cycles. Options: nol-no output listing (default) l-do an output listing noc-no cycle number count (default) c-turn on cycle count using zero initial value contc-turn cycle count on, begin with last value cre-create a cross reference table (default anyway) RMB s-create a symbol table (default anyway) EQU Example: OPT l – Print source listing from this point

Homework 3 Solution Solution: Write a subroutine to save the first 5 odd (8-bit) numbers pointed to by the x-register (passed in) onto the stack. Solution: SUB1 LDAA #$05 PULY NEXT BRSET $00,X #$01 ODD INX BRA NEXT ODD LDAB $00,X PSHB DECA BNE NEXT PSHY RTS Note: For subroutine to execute in main program, a BSR or JSR command must be used in main program.

Homework 4 solution Write a program to output a square wave thru port S pin 2. The output can be observed on the scope, and the period T of the wave should be measured. More than one period wave should be generated. The machine cycle time of the MC9S12C32 should be estimated. Draw the square wave.

Homework 4 Solution Cont’d ORG $2000 FCB $XX FCB $04 ORG $1000 LDAA #$04 STAA $024A LDAB #$04 CYCLE LDAA $2001 3 STAA $0248 3 EORA #$04 1 STAA $2001 3 LDAA $2000 3 NEXT DECA 1 BNE NEXT 3/1 DECB 1 BEQ EXIT 3/1 JMP CYCLE 3 EXIT SWI END Address Opcode Postbyte Operand 1000 86 04 1002 7A 024A 1005 C6 04 1007 B6 2001 100A 7A 0248 100D 88 04 100F 7A 2001 1012 B6 2000 1015 43 1016 26 FD 1018 53 1019 27 03 101B 06 1007 101E 3F Configures PS2 as output. Helps us to output two periods. Outputs signal from PS2 Switch $2001(toggle) Delay (Note: BNE and BEQ take 3 machine cycles to execute if the branch is taken and one machine cycle if it is not taken) T/2=Machine Cycle Time*[3+3+1+3+3+COUNT*(1)+(COUNT-1)*3+1+1+3] (Note: Count = #$XX)

QUESTIONS???