Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

Similar documents
Chapter 6. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

ECE Test #1: Name

Arithmetic and Logic Instructions. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

Arithmetic,logic Instruction and Programs

The University of Texas at Arlington Lecture 7

Section 31. Instruction Set

16.317: Microprocessor-Based Systems I Summer 2012

Assembly Language Instructions

Chapter 5 Sections 1 6 Dr. Iyad Jafar

16.317: Microprocessor-Based Systems I Spring 2012

Lecture (04) PIC16F84A (3)

16.317: Microprocessor-Based Systems I Fall 2012

Flow Charts and Assembler Programs

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

4.5.1) The Label Field ) The Mnemonic Field. 4.5) Assembly Language Program Structure A PIC18 ALP consists of 3 type of statements:

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

SOLUTIONS!! DO NOT DISTRIBUTE!!

More (up a level)... Connecting the Nokia 3510i LCD to a Microchip PIC16F84 microcontroller

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 5 Solution

PIC 16F84A programming (II)

Discrete Logic Replacement Message Dispatch Engine

Instuction set

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

ECE Homework #3

EE 367 Introduction to Microprocessors Homework 6

/ 40 Q3: Writing PIC / 40 assembly language TOTAL SCORE / 100 EXTRA CREDIT / 10

D:\PICstuff\PartCounter\PartCounter.asm

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE. E4160 Microprocessor & Microcontroller System. Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010

EXPERIMENT 4: Parallel Input/Output. Objectives Introduction to the Parallel Input/Output (I/O) Familiarization to Interfacing

The University of Texas at Arlington Lecture 5

ALU and Arithmetic Operations

S w e d i s h c r. w e e b l y. c o m j a l i l a h m e l i v e. c o m Page 1

The University of Texas at Arlington Lecture 3

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

Tutorial for PICMON18 Debug Monitor

APPLICATION NOTE 2361 Interfacing an SPI-Interface RTC with a PIC Microcontroller


16.317: Microprocessor Systems Design I Fall 2015

Q1: Multiple choice / 20 Q2: Protected mode memory accesses. / 40 Q3: Reading PIC. / 40 assembly language TOTAL SCORE / 100

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

PIC Architecture & Assembly Language Programming. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Interrupts. ELEC 330 Digital Systems Engineering Dr. Ron Hayne. Images Courtesy of Ramesh Gaonkar and Delmar Learning

PIC PROGRAMMING START. The next stage is always the setting up of the PORTS, the symbol used to indicate this and all Processes is a Rectangle.

Application Note - PIC Source Code v1.1.doc

Controller Provides Display of Monitored Process Deviation

EEE111A/B Microprocessors

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Done 1 NVB THF TLF T/R POL 1SHOT. Figure 1: Status register

A Better Mouse Trap. Consumer Appliance, Widget, Gadget APPLICATION OPERATION: Ontario, Canada

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

When JP1 is cut, baud rate is Otherwise, baud rate is Factory default is that JP1 is shorted. (JP1 is jumper type in some model)

ECE 354 Introduction to Lab 2. February 23 rd, 2003

ECE 354 Computer Systems Lab II. Interrupts, Strings, and Busses

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

CS 3843 Final Exam Fall 2012

PIC Discussion. By Eng. Tamar Jomaa

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE Microcontroller Based System Design

15213 Recitation 2: Floating Point

Jordan University of Science and Technology Electrical Engineering Department Microcontrollers and Embedded Systems Spring 2011

Interfacing PIC Microcontrollers. ADC8BIT2 Schematic. This application demonstrates analogue input sampling

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

16.317: Microprocessor Systems Design I Fall Exam 3 December 15, Name: ID #:

16.317: Microprocessor Systems Design I Fall 2014

CPSC 213. Introduction to Computer Systems. Reading. Control Flow. Loops (S5-loop) Static Control Flow. Unit 1d. Companion.

MC9S12 Address Space

CPSC 213. Introduction to Computer Systems. Static Control Flow. Unit 1d

How Stuff Works: Processors

ME 515 Mechatronics. A microprocessor

IEEE-754 floating-point

CSCI 2212: Intermediate Programming / C Chapter 15

;=============================================================== ;RAM locations in Access bank, uninitialized UDATA_ACS

/ 28 HLL assembly Q4: Conditional instructions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

COMP2611: Computer Organization. Data Representation

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

COMP Overview of Tutorial #2

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

16.317: Microprocessor Systems Design I Spring 2015

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

Simon. Final Project Report December 11, 2009 E155. Julia Karl and Kirsten McAfee

Embedded System Design

Computer Organisation CS303

/* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */

Chapter 13. PIC Family Microcontroller

COMP2121: Microprocessors and Interfacing. Number Systems

Venstar Thermostat Adapter

These 3 registers contain enable, priority,

Floating Point Numbers

ECE 354 Computer Systems Lab II. Memory and Indirect Addressing

Weekly Report: Interactive Wheel of Fortune Week 4 02/014/07-02/22/07 Written by: Yadverinder Singh

Binary Outputs and Timing

Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

Architecture. Harvard Architecture. PIC18 Review. Architecture, Instruction Set, and Assembly Language Programming

Transcription:

Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code. 1S. Prior to execution of the following code segment, PC was 0x0120, WREG was 0x02 and register file 0x81 was 0x35. ADDWF MOVWF ADDWF RRNCF GOTO 0x81,0,0 0x82 0x81,1,0 0x81 0x029A After the execution of the above the code segment, determine: a) The content of register files 0x81, 0x82 and WREG. b) The content of PC. a) Register 0x81 0x36 Register 0x82 0x37 WREG 0x37 b) PC 0x029A 1U. Prior to execution of the following code segment, PC was 0x0220, WREG was 0xA2 and register file 0x83 was 0x45. ADDWF MOVWF ADDWF RRNCF GOTO 0x83,0,0 0x82 0x83,1,0 0x83 0x029A After the execution of the above the code segment, determine: a) The content of register files 0x83, 0x82 and WREG. b) The content of PC. 2S. Write an assembly code segment that implements the following C code, where the value of op1 and op2 are in the register files 0x92 and 0xA0. If (op1 > op2) { op1 = 23; op2 = 29; Op1 Op2 equ 0x92 equ 0xA0 MOVF Op1, 0 CPFSLT Op2 www.engrcs.com Computer Organization and Microprocessors, V3.0d page 27

Next: BRA Next MOVLW 23 MOVWF Op1 MOVLW 29 MOVWF Op2 2U. Write an assembly code segment that implements the following C code, where the value of op1 and op2 are in the register files 0x81 and 0x82. If (op1 op2) { op1 = op1 + 93; op2 = 0; 3S. Write an assembly code segment that implements the following C code, where the value of index and count in memory locations 0xC2 and 0xC5. for (index=0 ; index<26; index++){ Count = Count + 2 index equ 0xC2 count equ 0xC5 MOVLW 26 CLRF index CLRF count floop: INCF 0xC2 INCF 0XC5 INCF 0XC5 CPFSEQ 0xC2 BRA floop 3U. Write an assembly code segment that implements the following C code, where the value of index and count in register files 0xA2 and 0xA3. for (index=5 ; index<25; index=index+2){ Count = Count + 4; 4S. Write an assembly code that set the contents of registers 0xA1 through 0xA8 (unique value in each register) such that the logical AND of the registers results in 0x00 and logical OR results in 0xFF. // there are eight registers with 8-bits each so simply setting only one unique bit // in each register will satisfy the requirements MOVLW 0x01 MOVWF 0xA1 MOVFF 0xA1, 0xA2 0xA2 www.engrcs.com Computer Organization and Microprocessors, V3.0d page 28

MOVFF MOVFF MOVFF MOVFF MOVFF MOVFF 0xA2, 0xA3 0xA3 0xA3, 0xA4 0xA4 0xA4, 0xA5 0xA5 0xA5, 0xA6 0xA6 0xA6, 0xA7 0xA7 0xA7, 0xA8 0xA8 4U. Write an assembly code that set the contents of register files 0xA1 through 0xA8 (unique value in each register) such that the logical XOR of all the registers results in 0x00. 5S. Write an assembly code that reads the value of register 0xD1, doubles it and saves it in register 0xD2, quadruple of the value and save it in register file 0xD3 and half the read value to register file 0xD4. MOVF 0xD1,0 // read the value MOVWF 0xD2 0xD2 // multiply by 2 <shift left> BCF 0xD2,0 // just to clear carry MOVFF 0xD2, 0xD3 0xD3 // multiply by 2 <shift left> BCF 0xD3,0 // just to clear carry MOVWF 0xD4 RRNCF 0xD4 BCF 0xD4,7 // Divide by 2 <shift right> 5U. Write an assembly code that reads the value of register file 0xA8, writes the bits in reverse order in register 0x8A. Upon execution of the code, bit 0 of register 0xA8 will be in bit 7 of register 0x8A and bit 7 of register 0xA8 will be in bit 0 of register 0x8A. 6S. Write an assembly code that clears (0x00) registers 0x80 through 0x91 and then sets the value of register listed on the right column to 0xFF if the corresponding value in the left column is equal to the value in the register 0xA1. For example if the value in 0xA1 register is 4, only register 0x83 should be set to oxff. Content of register 0xA1 Register file to be set to 0xff 1 0x81 2 0x86 3 0x87 4 0x83 8 0x84 9 0x91 All other values 0x80 www.engrcs.com Computer Organization and Microprocessors, V3.0d page 29

; Clear Registers - You can use indirect addressing (Chap6) to set the values in a loop CLRF 0x80 CLRF 0x81 CLRF 0x82 CLRF 0x83 CLRF 0x84 CLRF 0x85 CLRF 0x86 CLRF 0x87 CLRF 0x88 CLRF 0x89 CLRF 0x8A CLRF 0x8B CLRF 0x8C CLRF 0x8D CLRF 0x8E CLRF 0x8F CLRF 0x90 CLRF 0x91 ; Setting the values MOVLW 1 BRA Cont2 BRA L81 Cont2: MOVLW 2 BRA Cont3 BRA L86 Cont3: MOVLW 3 BRA Cont4 BRA L87 Cont4: MOVLW 4 BRA Cont8 BRA L83 Cont8: MOVLW 8 BRA Cont9 BRA L84 Cont9: MOVLW 9 BRA Other BRA L91 L81: MOVLW 0xFF MOVWF 0x81 L86: MOVLW 0xFF MOVWF 0x86 L87: MOVLW 0xFF MOVWF 0x87 L83: MOVLW 0xFF MOVWF 0x83 www.engrcs.com Computer Organization and Microprocessors, V3.0d page 30

L84: MOVLW 0xFF MOVWF 0x84 L91: MOVLW 0xFF MOVWF 0x91 Other: MOVLW 0xFF MOVWF 0x80 Done: 6U. Write an assembly code that clears (0x00) registers 0x81 through 0x8A and then sets the value for each of these registers to sum of the address of its digits if the sum is even. For example location 0x82 will be set to 0xA but content of location 0x83 will not be changed. 7S. Write an assembly code that sorts the values stored in register files 0x90 through 0x94 from the largest to smallest. list p=18f1220 radix hex temp equ 0x80 temp1 equ 0x90 temp2 equ 0x91 temp3 equ 0x92 temp4 equ 0x93 temp5 equ 0x94 org 0x0000 COMP12: MOVF temp1,0 CPFSGT temp2 ; If temp1 > tempt2, then skip next line GOTO COMP13 MOVFF temp1, temp MOVFF temp2, temp1 MOVFF temp, temp2 COMP13: CPFSGT temp3 ; If temp1 > temp3, then skip next line GOTO COMP14; To skip MOVFF temp1, temp MOVFF temp3, temp1 MOVFF temp, temp3 COMP14: CPFSGT temp4 ; If temp1 > temp4, then skip next line GOTO COMP15 ; swap values MOVFF temp1, temp MOVFF temp4, temp1 MOVFF temp, temp4 www.engrcs.com Computer Organization and Microprocessors, V3.0d page 31

COMP15: CPFSGT temp5 ; If temp1 > temp5 skip next line. GOTO COMP23 MOVFF temp1, temp MOVFF temp5, temp1 MOVFF temp, temp5 COMP23: MOVF temp2,0 CPFSGT temp3 ; If temp2 > temp3, skip next line GOTO COMP24 ; Skipped line MOVFF temp2, temp MOVFF temp3, temp2 MOVFF temp, temp3 COMP24: CPFSGT temp4 ; If temp2 > temp4, skip a next line GOTO COMP25 ; Skipped line MOVFF temp2, temp MOVFF temp4, temp2 MOVFF temp, temp4 COMP25: CPFSGT temp5 ; If temp2 > temp5, skip a next line GOTO COMP34 ; skipped line MOVFF temp2, temp MOVFF temp5, temp2 MOVFF temp, temp5 COMP34: MOVF temp3,0 CPFSGT temp4 ; If temp3 > temp4, skip a next line GOTO COMP35 ; skipped line MOVFF temp3, temp MOVFF temp4, temp3 MOVFF temp, temp4 COMP35: CPFSGT temp5 ; If temp3 > temp5, skip a next line GOTO COMP45; skipped line MOVFF temp3, temp MOVFF temp5, temp3 MOVFF temp, temp5 COMP45: endpro: MOVF temp4,0 CPFSGT temp5 ; If temp4 > temp5, skip a next line GOTO endpro MOVFF temp4, temp MOVFF temp5, temp4 MOVFF temp, temp5 end www.engrcs.com Computer Organization and Microprocessors, V3.0d page 32

7U. Write an assembly code that sorts the values stored in register files 0x90 through 0x94 from the smallest to largest. 8S. What is the real number represented by the following single precision floating point representation: Bit 31 Bit 0 1111 0101 0101 1100 0000 0000 0000 0000 Sign bit is 1 Negative number Power = Exponent Bias = (11101010) 2 127 = 234 127 = 107 Fraction = 2-1 + 2-3 +2-4 + 2-5 = 0.71875 Real Number = - 1.71875 x 2 107 = - 2.788831 x 10 32 8U. What is the real number represented by the following single precision floating point representation: Bit 31 Bit 0 0111 0101 1111 1010 0000 0000 0000 0000 9S. Write the real number 1.375 x 16 in double precision floating point format. Real Number = 1.375 x 2 4 Positive Sign bit is 0 Exponent = Power + Bias Convert to nearest 1.ffff x 2 power with the available precision Double Precision Floating Point (64 bits): [0] [1000 0000 011] [0110 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000] 9U. Write the real number {1.875 / 16 in double precision floating point format. 10S. Write an Assembly code that compare two single float numbers where one of number, op1, is stored in register files 0x80 through 0x83 and the second number, op2, is stored in register files 0x84 through 0x87 as shown below:. www.engrcs.com Computer Organization and Microprocessors, V3.0d page 33

Op1: Bit 31... Bit 24 Bit 23... Bit 16 Bit 15... Bit 8 Bit 7... Bit 0 0x83 0x82 0x81 0x80 Op2: Bit 31... Bit 24 Bit 23... Bit 16 Bit 15... Bit 8 Bit 7... Bit 0 0x87 0x86 0x85 0x84 If Op1 is larger than Op2 set Wreg to 0xFF. Flow Chart Start Wreg 0x00 Op1 >0 Byte-by-Byte Comparison Op1 > Op2 Op2 >0 Wreg 0xFF Op2 >0 Byte-by-Byte Comparison Op1 > Op2 Done ; Code to implement the comparison ; SIGN equ 0x90 OP1GTOP2 equ 0x91 www.engrcs.com Computer Organization and Microprocessors, V3.0d page 34

. CLRF WREG CLRF SIGN CLRF OP1GTOP2. ; Determine the signs BTFSC 0x83,7 BRA OP1N BRA OP1P OP1P: BTFSC 0x87,7 BRA OP1P_OP2N BRA OP1P_OP2P OP1N: BTFSC 0x87,7 BRA OP1N_OP2N BRA OP1N_OP2P OP1P_OP2N: ; OP1 is positive and OP2 is negative SETF WREG BRA DONE OP1N_OP2P: ; OP1 is negative and OP2 is positive CLRF WREG. BRA DONE OP1N_OP2N: CALL COMP_BYTES MOVLW 1. CPFSEQ OP1GTOP2. SETF WREG BRA DONE OP1P_OP2P: CALL COMP_BYTES CLRF WREG. CPFSEQ OP1GTOP2. SETF WREG BRA DONE. ; wait loop Done: COMP_BYTES: ; Compare bytes and return 1 if OP1 is larger and 0 otherwise BYTE3: MOVF BRA OP1BN OP1BP: MOVLW 0xFF OP1BN: MOVLW 0 OP1NB: MOVLW 0 BRA OP1NBN OP1NBP: MOVLW 0 OP1NB: MOVLW 0xFF RETURN www.engrcs.com Computer Organization and Microprocessors, V3.0d page 35

10U. Write an assembly code that compare two double precision float numbers where one is in op1 (registers A0 to A7) and the other is in op2 (registers B0 to B7). If op1 is less than op2 set register 0x80 to 0x00, otherwise set register 0x80 to 0xFF. 11S. Use CPFSLT instruction to implement the following C code functionality: // high is in Wreg and temp is in register file 0x81 high =0 If (temp 5 ) { high = 1; Flow Chart Start Reg 0x81 < 5 Wreg = 1 Wreg = 0 Done Code MOVLW 5 CPFSLT 0x81 BR WR_One MOVLW 0 WR_One: MOVLW 1 Done: BR Done 11U. Use CPFSLT instruction to implement the following C code functionality: // high is in Wreg and temp is in register file 0x84 high =1 If (temp < 15 ) { high = 0; www.engrcs.com Computer Organization and Microprocessors, V3.0d page 36

12U. Write a PICmicro Assembly code that does the following: Accepts temperature in Centigrade ranging from 0 to 127 oc on Port A. Output the temperature in Fahrenheit ranging from 1 to 126 on Port B. 0 output represent too low to show temperature and 127 represents too high to show. te: use Tf = (2Tc + 32) for conversion. Every hour, the temperature in oc is stored in registers starting at 0xA0 and will keep the data for 24 hours. te: first temp is stored in 0xA0 and the 24th is stored in 0xB7 and 25th is stored in 0xA0. All temperature reading in location 0xA0 through 0xB7 will be cleared when INT0 pin transitions from High to low. www.engrcs.com Computer Organization and Microprocessors, V3.0d page 37