LECTURE #21: G-CPU & Assembly Code EEL 3701: Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz

Similar documents
Menu Computer Organization Programming Model for the an example microprocessors (the G-CPU & Motorola 68HC11) Assembly Programming Look into my...

Homework 12 Solutions

ME4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 7

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

Total: EEL 3701 Digital Logic & Computer Systems Final Exam Fall Semester 2007 COVER SHEET: Re-Grade Information: 1 (10) 2 (10) 3 (10) 4 (14) 5 (14)

Y = (A + C) (A + B) (B + C)

538 Lecture Notes Week 2

Chapter 2: HCS12 Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

Lecture 5 Assembly Programming: Arithmetic

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Lecture 6 Assembly Programming: Branch & Iteration

EE 3170 Microcontroller Applications

ME 6405 Introduction to Mechatronics

Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

1. Memory Mapped Systems 2. Adding Unsigned Numbers

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

CodeWarrior. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Most of the HC12 s instructions access data in memory There are several ways for the HC12 to determine which address to access

Exam I Review February 2017

Programming the Motorola MC68HC11 Microcontroller

Mark II Aiken Relay Calculator

ECE 3120 Computer Systems Arithmetic Programming

Cross Assembly and Program Development

It translates (converts) assembly language to machine code.

Lecture 9 Subroutines

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

EE319 K Lecture 7. Address mode review Assembler, Debugging Psuedo ops 16 bit timer finite state machines. University of Texas ECE

Introduction to Programming

ECE 372 Microcontroller Design Assembly Programming Arrays. ECE 372 Microcontroller Design Assembly Programming Arrays

N bit is set if result of operation in negative (MSB = 1) Z bit is set if result of operation is zero (All bits = 0)

2) [ 2 marks] Both of the following statements cause the value $0300 to be stored in location $1000, but at different times. Explain the difference.

ECE3120: Computer Systems Hardware & Software Development Tools

HC11 Instruction Set Architecture

HC11 Instruction Set Architecture

538 Lecture Notes Week 3

Introduction to the 9S12 Microcontroller

Lecture 7 Assembly Programming: Shift & Logical

Introduction to Microcontrollers

Using the stack and the stack pointer

Computer Organization I. Lecture 28: Architecture of M68HC11

Exam 1 Feb. 23, 25, 27?

Serial Communication Through an Asynchronous FIFO Buffer

ECET Chapter 2, Part 3 of 3

COSC 243. Instruction Sets And Addressing Modes. Lecture 7&8 Instruction Sets and Addressing Modes. COSC 243 (Computer Architecture)

A Simple MC9S12 Program

ECE L A B 1 Introduction ASSEMBLY PROGRAMMING WITH MINIIDE

68000 Architecture, Data Types and Addressing Modes. 9/20/6 Lecture 2 - Prog Model 1

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3. You will be able to use all of the Motorola data manuals on the exam.

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

What is an Addressing Mode?

Introduction to Computers - Chapter 4

EMCH 367 Fundamentals of Microcontrollers Example_Sort EXAMPLE SORT

Menu. >Debugging/Simulating in Atmel Studio >Downloading and Debugging/Emulating with the UF-board. Machine Codes 6811: $86 $0A GCPU: $02 $0A

Introduction to Embedded Systems and Chapter 1: Introduction to HCS12/MC9S12. EE383: Introduction to Embedded Systems University of Kentucky

68000 Assembler by Paul McKee. User's Manual

CMPEN 472 Sample EXAM II

Sample Problem Set #1

ECET Chapter 2, Part 2 of 3

ECE 4510/5530 Microcontroller Applications Chapter 1

MC9S12 Address Space

Chapter 2 HCS12 Assembly Language

EE 308 Spring The HCS12 has 6 addressing modes

Macro Assembler. Defini3on from h6p://

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

Wed. Sept 6 Announcements

CE-320 Microcomputers I Winter 2010 LAB 1: MINIIDE GROUP #: NAME: PARTNER: Lab 1 Page 1

C SC 230 Computer Architecture and Assembly Language April 2000 Exam Sample Solutions

538 Lecture Notes Week 5

ECE 331: PC Lab 3 Stack and Subroutines

2. Arithmetic Instructions addition, subtraction, multiplication, divison (HCS12 Core Users Guide, Sections 4.3.4, and ).

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1

ECE 3120 Lab 1 Code Entry, Assembly, and Execution

Module 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function

538 Lecture Notes Week 5

ECE/CE 3720: Embedded System Design

Lecture 11: Advanced Arithmetic Instructions

Outline. 2.8 Stack. 2.9 Subroutines

ORG ; TWO. Assembly Language Programming

The Motorola 68HC11 Instruc5on Set

m 1 se 7 m 23 Introduction to Embedded Microcomputer Systems Lecture 16.1 Recap Finite State Machines Pointer implementation

Assembly Language. Instructor: Dmitri A. Gusev. Spring Lecture 10, February 27, CSC : Introduction to Computer Science

Processor design - MIPS

Module 1-G. Marcos and Structured Programming

Lab 7: Asynchronous Serial I/O

Harry H. Porter, 2006

Program Development. Chapter 5

Ryerson University Department of Electrical and Computer Engineering ELE 538 Microprocessor Systems Final Examination December 8, 2003

Introduction to Microcomputer Systems Addressing modes

S12CPUV2. Reference Manual HCS12. Microcontrollers. S12CPUV2/D Rev. 0 7/2003 MOTOROLA.COM/SEMICONDUCTORS

Introduction to Microcontrollers II

History of the Microprocessor. ECE/CS 5780/6780: Embedded System Design. Microcontrollers. First Microprocessors. MC9S12C32 Block Diagram

HC 11 Instructions! From Alex Hollowayʼs notes with! many thanks!

Professor E. Ambikairajah UNSW Sydney

Addressing Modes. To review data transfer instructions and applying the more advanced addressing modes.

Introduction to Microcontrollers II

Exam 2 E2-1 Fall Name: Exam 2

ECE 3610 MICROPROCESSING SYSTEMS

Transcription:

LECTURE #21: G-CPU & Assembly Code EEL 3701: Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz G-CPU Important Notes (see Schwartz s lecture for a general overview) - The G-CPU is little endian, meaning the LSB is stored and loaded before the MSB in a 16-bit word (as opposed to big endian). - The conditional code register (CCR) contains a negative (N) flag and a zero (Z) flag, which are only dependent on register A. - The memory used in the G-CPU is synchronous. For this reason, a memory clock (MCLK) is used to drive the SRAM and EPROM. Two T flipflops are used in series to create a system clock (CLOCK ) that is 1/4 th the speed of the memory clock. In this way, we can pretend that the SRAM and EPROM are running asynchronously to the system. - The SRAM used in the G-CPU has both input data lines (for writing) and output data lines (for reading). - The exhaustive next state truth table (NSTT) that is stored in the memory for implementing the controller has 2 14 possible states/addresses. - Branch statements (BRA, BEQ, BN, BP) only modify the lowest byte of an address. For this reason, you cannot jump past certain break points (where the ninth bit changes). Assembly Language Format Instruction Set: A list of all the operations that can be performed by a μprocessor. General format for an instruction (on the MC68HC11): Label: Operation-Mnemonic Operand(s) ;Comments - A label is a symbolic name for the address of an instruction. - A label is not required and is generally only used when necessary. - The colon (:) is optional and is not considered part of the label. - Labels are used with branch and jump statements. - Labels can be used to point to a specific address containing data. - An operation-mnemonic is an abbreviation that corresponds to a command. - Note: A mnemonic is a memory aid. - An operand denotes the object to be operated upon. - An operand may represent an address, register, or immediate data. - Comments are used to explain code, making it easier to follow. - The assembler I used in college denoted comments with a semi-colon. (Look at the instruction set for the G-CPU.) Page 1 of 6

Addressing Modes Effective Address: The address of the data operated on by an instruction. - You should be able to find the effective address for: - Immediate Addressing (the address of the operand pointed to by the PC) - Extended Addressing - Direct Addressing - Indexed Addressing - Inherent Addressing - Addressing is inherent to the instruction (usually used with registers). - Examples: TAB INX SUM_BA - Immediate Addressing (denoted by a # symbol) - The operand is the data to be used by the instruction. - Examples: LDAA #$42 LDX #$1B00 (You cannot STAA #$42. Why?) Note: Certain symbols indicate the radix for a number: $ => Hexadecimal @ => Octal % => Binary => ASCII (none) => Decimal - Extended Addressing - The operand gives the address where the data is stored. - Examples: LDAA $1300 STAA $1400 LDX $1301 - Direct Addressing (the G-CPU does not have this type of addressing) - Similar to extended addressing, except: - The upper address byte is assumed to be $00 - Direct addressing only accesses the address range $0000-$00FF - $0000 to $00FF is called the direct page - Direct addressing is faster than extended addressing - Examples: LDAA $A0 STAA $B0 LDX $C0 Note: The assembler knows the difference between extended because only one byte was given for the address. Page 2 of 6

- Indexed Addressing - Gives the address relative to the address in an index register (IX or IY). - The number supplied is a displacement/offset. - Displacements are (positive) unsigned binary, ranging from $00 to $FF. - Examples: LDAA 0,X STAA $2A, Y Note: IX and IY remain unchanged. - Relative Addressing (the G-CPU does not have this type of addressing) - Similar to indexed, but used to change the Program Counter (PC). - Displacements are 2 s complement, ranging from $00 to $FF. - Generally, used with branch statements. - Examples: BEQ $FE ;Branches back 2 addresses BNE $04 ;Branches forward 4 addresses Note: The MC68HC11 has memory-mapped I/O, meaning that its input and output ports are accessed using the same addressing modes as memory (discussed above). Assembler Directives Assembly control: ORG => Sets the origin (starting point) of the program or dataset Example: ORG $1300 Symbol Definition: EQU => Assigns a permanent value to a symbol name. Example: Answer EQU $42 (Note: Answer can be used anywhere the value $42 could be used.) Data Definition/Storage Allocation: DC.B => Define constant byte (allocates and initializes memory) Examples: (label) DC.B $42, $AB, $F0, 64 DC.W => Define constant word (allocates and initializes memory) Example: (label) DC.W $42AB, $F040 DS.B => Define storage bytes (allocates uninitialized memory space) Example: (label) DS.B 4 DS.W => Define storage word (allocates uninitialized memory space) Example: (label) DS.W 2 Page 3 of 6

Example Code Given a location in memory containing a dataset of X consecutive, 8-bit, unsigned binary numbers, write a program that adds the numbers together and stores the result in another portion of memory. The dataset at the given memory location is organized as follows: - X is the first byte and is an unsigned binary number indicating how many numbers must be added together to obtain the result. - Next is the address where the sum should be stored. - Finally, the dataset of consecutive, 8-bit, unsigned binary numbers. (Note: You may ignore problems with overflow/roll-over.) ORG $19FF ;Table in SRAM (Given) DS.B 1 Dataset DC.B 3 ;X DC.W $FF19 ;Address to store the sum (little endian). DC.B $4A, $11, $24 ;Dataset ORG $0000 ;G-CPU always starts at $0000 LDX #Dataset ;IX points to dataset (Dataset address is a given) LDAA 0,X ;RegA gets counter INX LDY 0,X ;IY points to storage location LDAB #$00 STAB 0,Y ;Initialize current sum to zero INX Loop INX STAA Counter ;Save counter LDAA 0,X ;Get next value LDAB 0,Y ;Get current sum SUM_AB ;Add current numbers into RegB STAB 0,Y ;Save current sum LDAB #NegOne LDAA Counter ;Get counter SUM_BA ;Decrement counter BNE Loop ;Repeat until count is zero (all numbers are added) Done BEQ Done ;End program ORG $1000 ;Storage values must be in SRAM (not EPROM) Counter DS.B 1 ;Storage for the counter NegOne EQU $FF ;To decrement, we must add a 2 s complement -1. Note: We wrote the code using indexed addressing so that it is a general program that can be used for any memory location (as opposed to hard coded to a specific address). Page 4 of 6

So what happens next? We created our program in a text editor. This is called our source file. Next we use and assembler to assemble our program, generating 2 files: - The List file is a human readable file containing: - Addressing information - Machine code (only binary/hexadecimal) - Assembly code (the program) - The Object file is the assembled machine code the μprocessor will use. We simulate and debug the program at this point. The final Object file is then downloaded to memory so the μprocessor can run it. Hand Assembly There is no G-CPU assembler, so we need to hand assemble the code. - Use the G-CPU Instruction Set (found in the G-CPU documentation). Addresses Machine Code Labels Assembly Code ORG $19FF $19FF $XX DS.B 1 $1A00 $03 Dataset DC.B 3 $1A01-$1A02 $FF $19 DC.W $FF19 $1A03-$1A05 $4A $11 $24 DC.B $4A, $11, $24 ORG $0000 $0000-$0002 $08 $00 $1A LDX #Dataset $0003-$0004 $0C $00 LDAA 0,X $0005 $30 INX $0006-$0007 $?? $00 LDY 0,X $0008-$0009 $03 $00 LDAB #$00 $000A-$000B $13 $00 STAB 0,Y $000C $30 INX $000D $30 Loop INX $000E-$0010 $06 $00 $10 STAA Counter $0011-$0012 $0C $00 LDAA 0,X $0013-$0014 $0F $00 LDAB 0,Y $0015 $15 SUM_AB $0016-$0017 $13 $00 STAB 0,Y $0018-$0019 $03 $FF LDAB #NegOne $001A-$001B $04 $00 $10 LDAA Counter $001C $14 SUM_BA $001D-$001E $21 $0D BNE Loop $001F-$0020 $20 $1F Done BEQ Done ORG $1000 $1000 $XX Counter DS.B 1 NegOne EQU $FF Note: The G-CPU cannot perform the LDY 0,X operation See next page for solutions. Page 5 of 6

Possible ways to work around the LDY 0,X problem: Option 1: Add a label at $1A01 called Address: LDY Address Option 2: Rearrange the table so that the storage address comes before X. LDY Dataset (You must increment IX twice before retrieving the counter.) Option 3: Define a space to save the address and load IY from there. LDAB 0,X STAB LSB LDAB 1,X STAB MSB LDY LSB... ORG $1001 LSB DS.B 1 MSB DS.B 1 Page 6 of 6