Homework 12 Solutions

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

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)

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

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

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)

Lecture 6 Assembly Programming: Branch & Iteration

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

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

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

Programming the Motorola MC68HC11 Microcontroller

Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Exam I Review February 2017

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

Lecture 9 Subroutines

A Simple MC9S12 Program

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.

Using the stack and the stack pointer

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

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

538 Lecture Notes Week 2

EE 3170 Microcontroller Applications

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

Introduction to the 9S12 Microcontroller

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

Cross Assembly and Program Development

Mark II Aiken Relay Calculator

ECE L A B 1 Introduction ASSEMBLY PROGRAMMING WITH MINIIDE

Sample Problem Set #1

Introduction to Programming

Exam 1 Feb. 23, 25, 27?

Introduction to Microcontrollers

Introduction to Microcontrollers II

EE4390 Microprocessors

the SAP-2 I. Intro cmpt-150-arc Sections 8-8, 8-9, 9-4, 9-5, 9.6, We ll do this in bits and pieces, doing the beginning of each section first.

Introduction to Microcontrollers II

It translates (converts) assembly language to machine code.

1. Memory Mapped Systems 2. Adding Unsigned Numbers

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.

Lecture 11: Advanced Arithmetic Instructions

ECE 3610 MICROPROCESSING SYSTEMS

ECET Chapter 2, Part 3 of 3

ECE 3120 Computer Systems Arithmetic Programming

Outline. 2.8 Stack. 2.9 Subroutines

538 Lecture Notes Week 3

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

EE 308 Spring The HCS12 has 6 addressing modes

ECE 372 Microcontroller Design Basic Assembly Programming. ECE 372 Microcontroller Design Basic Assembly Programming

Module 1-G. Marcos and Structured Programming

ECE/CE 3720: Embedded System Design

Chapter 2 HCS12 Assembly Language

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

ECET Chapter 2, Part 2 of 3

Lecture 7 Assembly Programming: Shift & Logical

Wed. Sept 6 Announcements

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

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

ECE 331: PC Lab 3 Stack and Subroutines

EE319 K Lecture 3. Introduction to the 9S12 Lab 1 Discussion Using the TExaS simulator. University of Texas ECE

Serial Communication Through an Asynchronous FIFO Buffer

Computer Organization I. Lecture 28: Architecture of M68HC11

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

UNIVERSITY OF MANITOBA DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING. Term Test #2 Solution ECE 3610 MICROPROCESSING SYSTEMS

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

Table 1: Mnemonics Operations Dictionary. Add Accumulators Add B to Y. Add with carry to B. Add Memory to B. Add 16-bit to D And B with Memory

MC9S12 Address Space

ECE3120: Computer Systems Hardware & Software Development Tools

EMCH 367 Fundamentals of Microcontrollers Example_Sort EXAMPLE SORT

Introduction to Microcontrollers III

The Motorola 68HC11 Instruc5on Set

HC11 Instruction Set Architecture

HC11 Instruction Set Architecture

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

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

Lab 7: Asynchronous Serial I/O

Lecture 5 Assembly Programming: Arithmetic

ECE 3120 Lab 1 Code Entry, Assembly, and Execution

ECE 3610 MICROPROCESSING SYSTEMS AN ENCRYPTED ASCII CODE DECODER

Introduction to Microcontrollers III

EE 3170 Microcontroller Applications

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-470/570: Microprocessor-Based System Design Fall 2014.

COE538 Lecture Notes Week 3 (Week of Sept 17, 2012)

Exam 2 E2-1 Fall Name: Exam 2

Timing Generation and Measurements

COSC345 Software Engineering. Basic Computer Architecture and The Stack

HC11 Instruction Set

CMPEN 472 Sample EXAM II

538 Lecture Notes Week 5

ME 6405 Introduction to Mechatronics

Go Gators! Relax! May the Schwartz be with you!

538 Lecture Notes Week 5

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

Lecture #3 Microcontroller Instruction Set Embedded System Engineering Philip Koopman Wednesday, 20-Jan-2015

CHAPTER 8. Solutions for Exercises

MIPS Assembly Programming

What is an Addressing Mode?

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

Module 7: Address Registers & Array Processing

Transcription:

Page 1/6 1. Here is a short program that shows all addressing modes: We are given a table of student's test scores where there are three scores in a semester per student. Unfortunately, the person who entered the grades put them in the wrong order. They presently are in the following order. Student #1 test #2/test #3/test #1, Student #2 test #2/test #3/test #1 Student #200 test #2/test #3/test #1. We would like them to be in the following order. Student #1 test #1/test #2/test #3, Student #2 test #1/test #2/test #3 Student #200 test #1/test #2/test #3. Assume all scores start at 1000H (SRAM). N EQU 200 TABLE EQU $1000 NEG1 EQU %11111111 ; $FF ORG $1800 ; temporary data area TEMP DS.B 1 COUNT DS.B 1 ORG $0 LDAA #N ; (immediate addressing) STAA COUNT ; (extended addressing) LDX #TABLE ; ptr to top of table (immediate addressing) Loop_pt LDAB 0,X ; get test #2 score (indexed addressing) LDAA 1,X ; get test #3 score (indexed addressing) STAA TEMP ; save test #3 score in temp area (extended) LDAA 2,X ; get test #1 score (indexed) Re_order_data STAA 0,X ; store test #1 score (indexed) STAB 1,X ; store test #2 score (indexed) LDAA TEMP ; get test #3 score (extended) STAA 2,X ; store test #3 score (indexed) Check_counter LDAA COUNT ; retrieve count (extended) LDAB #NEG1 ; decrement counter (immediate) SUM_BA ; count = count -1 (inherent) * ABA ; equivalent to SUM_BA on 68HC11/12 BEQ END ; if count = 0 then end (branch addressing) STAA COUNT ; save count (extended) ; inc ptr (inherent) ; inc ptr (inherent) ; inc ptr (inherent) BNE Loop_pt ; if count!= 0 then loop (branch addressing) END BEQ END ; something to do (branch addressing)

Page 2/6 2. a) Here is the hand assembly (shown in two different formats) Address Data Instructions 0 08 LDX #$1100 1 00 2 11 3 02 LDAA #$10 4 10 5 06 STAA $1200 6 00 7 12 8 0C LOOP: LDAA 0,X 9 00 A 0E LDAB $10,X B 10 C 15 SUM_AB D 1F SHFB_R E 12 STAB $20,X F 20 10 30 11 03 LDAB #$FF 12 FF 13 04 LDAA $1200 14 00 15 12 16 14 SUM_BA 17 20 BEQ DONE 18 1E 19 06 STAA $1200 1A 00 1B 12 1C 21 BNE LOOP 1D 08 1E 20 DONE: BEQ DONE 1F 1E Address Data Instructions 0 08 00 11 LDX #$1100 3 02 10 LDAA #$10 5 06 00 12 STAA $1200 8 0C 00 LOOP: LDAA 0,X A 0E 10 LDAB $10,X C 15 SUM_AB D 1F SHFB_R E 12 20 STAB $20,X 10 30 11 03 FF LDAB #$FF 13 04 00 12 LDAA $1200 16 14 SUM_BA 17 20 1E BEQ DONE 19 06 00 12 STAA $1200 1C 21 08 BNE LOOP 1E 20 1E DONE: BEQ DONE This code grabs a number from Table #1 @ $1100 and a number from Table #2 @ $1110 and then computes an average value which is then stored in a Table #3, starting at $1120. b) This process is repeated 16 ($10) decimal times. c) We must save the count in a temporary memory location because the A register is corrupted inside the loop that retrieves the data and computes the average value.

Page 3/6 2. d) Re-written code. **************************************** Num EQU $10 Numx2 EQU NUM*2 ; $20 Neg1 EQU $FF ; 2 s complement minus 1 * Could replace the above line with a * Minus1 DC.B $FF * If did this replacement, would also need to change code. * The line LDAB #Neg1 would be replaced by * LDAB Minus1. **************************************** ORG $1200 Count DS.B 1 ORG $1100 Table DS.B Num ; for Table #1 DS.B Num ; for Table #2 DS.B Num ; for Table #3 **************************************** * Main program ORG $0 ; assembler directive (origin) to tell where code will be placed in memory LDX #Table ; pointer to data LDAA #Num ; counter value STAA Count ; counter will be saved in memory to free up a CPU register LOOP: LDAA 0,X ; get 1 st data value LDAB Num,X ; get 2 nd data value SUM_AB ; data1 + data2 SHFB_R ; divide sum by 2 STAB Numx2,X ; store average. value ; increment pointer LDAB #Neg1 ; -1 in 2 s complement format LDAA Count ; count = count 1 SUM_BA BEQ DONE ; branch to done if count is zero STAA Count ; else, save counter value BNE LOOP ; and repeat loop DONE: BEQ DONE ; loop forever

Page 4/6 3. Here is the program that corresponds to the machine code listed in problem #3: Addr Op Codes Instructions Comments ORG $100 $100 06 00 14 STAA $1400 ; temporarily store the A reg value $103 1A COMA ; /A $104 16 AND_BA ; /A*B $105 06 01 14 STAA $1401 ; save /A*B for future use $108 04 00 14 LDAA $1400 ; restore original A reg value $10B 1B COMB ; /B $10C 16 AND_BA ; A */B $10D 00 TAB $10E 04 01 14 LDAA $1401 ; retrieve /A*B $111 18 OR_BA ; (A*/B) + (/A*B) ORG $100 $100 06 00 14 STAA $1400 ; temporarily store the A reg value $103 1A COMA ; /A $104 16 AND_BA ; /A*B $105 06 01 14 STAA $1401 ; save /A*B for future use $108 04 00 14 LDAA $1400 ; restore original A reg value $10B 1B COMB ; /B $10C 16 AND_BA ; A */B $10D 00 TAB $10E 04 01 14 LDAA $1401 ; retrieve /A*B $111 18 OR_BA ; (A*/B) + (/A*B) This code performs the exclusive or of registers A and B (A xor B = A*/B + /A*B) and then returns this value in register A. Two temporary locations are required, 1400H and 1401H. 4. Code to count the number of (decimal) 37 s in memory from $1000-$107F: ********************************* * The final result is in Num37s and is also passed to the A register. ********************************* NUM EQU $7F+1 ; = $80 Neg1 EQU $FF Neg37 EQU $DB ; -37 = -$25 = -(%0010 0101) Table EQU $1000 * ; -(%0010 0101) => %1101 1010 + %1 = %1101 1011 = $DB ORG $1100 ; The below program uses these temporary locations that are reserved in memory Num37s DS.B 1 ; Keep track of the number of 37s found LoopCnt DS.B 1 ; Loop counter * Neg37 DS.B 1 ; Holds -37 value used to test if the current data is 37 ORG $0 LDAA #0 STAA Num37s ; Initialize the count of 37 s found to zero LDAA #NUM ; Initialize the loop counter (how many times the loop is executed) STAA LoopCnt ;... LDX #Table ; Initialize table pointer to point to the beginning of the table TOP LDAA 0,X ; Get first table value LDAB #Neg37 ; Get -37 SUM_BA ; Add table value to 37. If result is zero, table value was 37. BNE SKIP_INC ; If result is not zero, the table value was not 37, so don t increment.

Page 5/6 LDAA Num37s ; increment the number of $37s count value LDAB #1 SUM_AB STAB Num37s SKIP_INC LDAA LoopCnt LDAB #Neg1 ; Decrement loop counter SUM_BA ;... BEQ DONE STAA LoopCnt ; Increment the data pointer BNE TOP DONE LDAA Num37s WAIT BNE WAIT BEQ WAIT

Page 6/6 5. BRA $addr 000000 IR_LD INC_PC 000001 IR_5:0 BRA - 110010 110100 $addr => PCL Q5:0 IR5:0 Z N D5:0 MSA MSB MSC IR_LD RW PMXY SEL PC_LD M_LD X_LD Y_LD XD YD 000001 110010 - - 110100 01 10 0000 0 1 1000 00 00 00 00 00 0 0 110100 ------ - - 000000 01 10 0000 0 1 0000 00 10 00 00 00 0 0