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

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

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

ECE Test #1: Name

The University of Texas at Arlington Lecture 7

Chapter 5 Sections 1 6 Dr. Iyad Jafar

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

Discrete Logic Replacement Message Dispatch Engine

Directives & Memory Spaces. Dr. Farid Farahmand Updated: 2/18/2019

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

Section 31. Instruction Set

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

SOLUTIONS!! DO NOT DISTRIBUTE!!

16.317: Microprocessor-Based Systems I Fall 2012

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

Instuction set

Implementation of an Elliptic Curve Cryptosystem on an 8-bit Microcontroller

16.317: Microprocessor-Based Systems I Spring 2012

C Programming Language. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

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


Assembly Language Instructions

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

The University of Texas at Arlington Lecture 3

Personal SE. Computer Memory Addresses C Pointers

Lecture (04) PIC16F84A (3)

Tutorial for PICMON18 Debug Monitor

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

Arithmetic,logic Instruction and Programs

Flow Charts and Assembler Programs

The University of Texas at Arlington Lecture 5

16.317: Microprocessor-Based Systems I Summer 2012

HY-MCU Compiler User Manual

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

ECE331 Homework 4. Due Monday, August 13, 2018 (via Moodle)

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

ECE Homework #3

Chapter 10 Sections 1,2,9,10 Dr. Iyad Jafar

Final Exam. 11 May 2018, 120 minutes, 26 questions, 100 points

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

PIC 16F84A programming (II)

Advanced Induction. Drawing hands by Escher. Discrete Structures (CS 173) Madhusudan Parthasarathy, University of Illinois 1

EEE111A/B Microprocessors

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

Survey. Motivation 29.5 / 40 class is required

EE 367 Introduction to Microprocessors Homework 6

Microcontroller Systems. ELET 3232 Topic 8: Structures, Arrays, & Pointers

8/5/10 TODAY'S OUTLINE. Recursion COMP 10 EXPLORING COMPUTER SCIENCE. Revisit search and sorting using recursion. Recursion WHAT DOES THIS CODE DO?

General Instructions. You can use QtSpim simulator to work on these assignments.

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

15-213/18-243, Summer 2011 Exam 1 Tuesday, June 28, 2011

Hardware: Logical View

There are 16 total numbered pages, 7 Questions. You have 2 hours. Budget your time carefully!

Data Structures and Algorithms for Engineers

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

MPLAB C1X Quick Reference Card

CSCI 356 Fall 2017 : Practice Exam I DO NOT OPEN EXAM PACKET UNTIL INSTRUCTED TO DO SO YOU MAY FILL IN INFORMATION ON THE FRONT NOW

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

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

ECE 3610 MICROPROCESSING SYSTEMS

Chapter 3 Structured Program Development in C Part II

These 3 registers contain enable, priority,

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

The C Programming Language Guide for the Robot Course work Module

Where we are going (today)

PIC Discussion. By Eng. Tamar Jomaa

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

ME 6405 Introduction to Mechatronics

CS16 Exam #1 7/17/ Minutes 100 Points total

Final Exam. 12 December 2018, 120 minutes, 26 questions, 100 points

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

Instructions PLEASE READ (notice bold and underlined phrases)

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

LECTURE 17. Array Searching and Sorting

Midterm Exam Answers Instructor: Randy Shepherd CSCI-UA.0201 Spring 2017

Mod-5: PIC 18 Introduction 1. Module 5

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

CS2141 Software Development using C/C++ C++ Basics

Data Storage. August 9, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 August 9, / 19

CSE351: Memory, Data, & Addressing I

Introduction to Computer Science Midterm 3 Fall, Points

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

ECE 354 Computer Systems Lab II. Memory and Indirect Addressing

At the end of this module, the student should be able to:

C mini reference. 5 Binary numbers 12

SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017

X86 Assembly Language and C Fundamentals. Chapter 5. Data Transfer Instructions. X86 Code Figures

More about BOOLEAN issues

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

D:\PICstuff\PartCounter\PartCounter.asm

Programming (1.0hour)

CS , Fall 2002 Exam 1

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string.

Memory, Data, & Addressing I

Computer Science 50: Introduction to Computer Science I Harvard College Fall Quiz 0 Solutions. Answers other than the below may be possible.

Programming Fundamentals (CS-302 )

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA)

DEPARTMENT OF MATHS, MJ COLLEGE

University of California, Berkeley College of Engineering

MIPS Functions and the Runtime Stack

Transcription:

Chapter 6. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code. 1S. Write an assembly code equivalent for the following C code segment: int i; i=0; while (I < 35){ i = i+2; //int is 2 bytes i 0 equ 0x80 i 1 equ 0x81 // least significant byte of integer i // most significant byte of integer i CLRF i 0 CLRF i 1 MOVLW 35 w_loop: CPFSLT i 0 BRA done BRA cont cont: BRA w_loop done ; continue with the rest of the program 1U. Write an assembly code equivalent for the following C code segment: int i; // int is 2 bytes i=200; while (i < 126){ i = i-4; 2S. Write an assembly code equivalent for the following C code segment: int i; //int is 2 bytes for (i=5; i 29; i++) i = i+3; i 0 equ 0x80 i 1 equ 0x81 // least significant byte of integer i // most significant byte of integer i MOVLW 5 MOVWF i 0 www.engrcs.com Computer Organization and Microprocessors, V3.0d page 38

CLRF i 1 MOVLW 29 f_loop: CPFSGT i 0 BRA cont BRA done cont: BRA f_loop done ; continue with the rest of the program 2U. Write an assembly code equivalent for the following C code segment: int i; //int is 2 bytes for (i=15; i 129; i=i+2) i = i+6; 3S. Rewrite the following C code in assembly code and show the location of each variable in memory: float fnum; fnum = 200.625; fnum equ 0x80 ; 4 bytes ; convert 200.625 to single precision float 11001000.101 1.1001000101x2 7 ; 0100 0011 0100 1000 1010 0000 0000 0000 ; Use indirect addressing to move the 4 bytes into to fnum FSR0,0x80 ; Se the base MOVLW 0x00 MOVLW 0xA0 MOVLW 0x48 MOVLW 0x43 3U. Rewrite the following C code in assembly code and show the location of each variable in memory: float fnum; fnum = 1280.625; www.engrcs.com Computer Organization and Microprocessors, V3.0d page 39

4S. Rewrite the following C code in assembly code and show the location of each variable in memory: int id; char grade; float f_a[3]; struct student{ unsigned char name[40]; int grade; class [35]; class[3].grade = 100; id equ 0x80 ; 2 bytes grade equ 0x82 ; 1 byte f_a equ 0x83 ; 4 bytes each, 3 elements class equ 0x8F ; 40 + 2 bytes each, 35 elements MOVLW.100 // dot before the number indicated decimal MOVWF 0x135 CLRF 0x136 4U. Rewrite the following C code in assembly code and show the location of each variable in memory: int id; float f_a[5]; char grade; struct student{ unsigned char name[20]; int grade; class [15]; class[4].grade = 20; 5S. Write an assembly code segment using indirect addressing to implements the following C code segment: char name1 [32], name2[32]; char equ_flag; if (strcmp (name1, name2) equ_flag = 0; equ_flag = 1; name1 equ 0x80 ; 32 bytes name2 equ 0xA0 ; 32 bytes equ_flag equ 0xC0 ; 1 byte i equ 0xC1 ; 1byte CLRF FSR0, name1 ; set base FSR1, name2 i www.engrcs.com Computer Organization and Microprocessors, V3.0d page 40

CLRF equ_flg cmp: MOVF POSTINC0, 0 CPFSEQ POSTINC1 BRA done ; not equal INCF i MOVLW.31 CPFSGT i BRA cmp ; continue comparing INCF equ_flg ; strings are equal done: 5U. Write an assembly code segment using indirect addressing to implements the following C code segment: char apt1 [24], apt2[24]; char next; if (strcmp (apt1, apt2)) next = 0; next = 1; 6S. Write an assembly code segment using indirect addressing to implements the following C code segment: char source[48], dest[48]; char I; for (i=0; i<48 ; i++){ dest[i] = source[i]; source equ 0x80 ; 48 bytes dest equ 0xB0 ; 48 bytes i equ 0xE0 ; 1 byte CLRF FSR0, source ; set base FSR1, dest i xfer: MOVFF POSTINC0, POSTINC1 INCF i MOVLW.47 CPFSGT i BRA xfer 6U. Write an assembly code segment using indirect addressing to implements the following C code segment: char source[43], exch[43], temp; int i; www.engrcs.com Computer Organization and Microprocessors, V3.0d page 41

i=0; while (i<43){ temp = exch[i]; exch[i] = source[42 - i]; source[42-i] = temp; i++; 7S. Using MPLAB and the following sample Bubble Sort C code, write equivalent PICmicro assembly code using indirect addressing. void Bsort( int data[20] ) { int temp, i, swapped; swapped = 1; while (swapped == 1){ swapped = 0; for (i=0; i<20 ; i++){ if (data[i] > data[i+1]){ temp = data[i]; data[i]= data[i+1]; data[i+1]=temp; swapped = 1; // if() // for() // while() //Bsort() 0, 0x90 ; prep with first address 1, 0x91 ; prep with the address after the first Loop2: MOVF INDF0, W ; copy value at FSR0 to WREG CPFSGT INDF1 ; compare WREG with FSR1 BRA NGT1 ; if!( (FSR0) > (FSR1) ) ;swap the value of FSR0 is already cached in WREG MOVFF INDF1, INDF0 ; move FSR1 to FSR0 MOVWF INDF1 ;move prev value of FSR0 into FSR1 MOVF POSTINC0 ; temp increment addr of FSR0 ; time to reset the FSR1 address... ; ; FSR0 only moves when FSR1 reaches the end and is never reset backwards MOVFF FSR0L, FSR1L ; copy address of FSR0 to FSR1 MOVFF FSR0H, FSR1H MOVF POSTDEC0 ; decrement FSR0 back to it's proper value BRA Loop2 NGT1: MOVF POSTINC1 ; increment FSR1 ; this is a specialized piece, for a general case we have to load in the end value ; and compare the low and high bytes MOVLW 0x95 ; move the end address into WREG CPFSEQ FSR1L ;compare with the ONLY the low byte BRA Loop2 ; not equal..continue ;is equal.. increment FSR0 and reset FSR1 to FSR0+1 MOVF POSTINC0 ; increment FSR0 MOVF POSTINC0 ; increment FSR0 (temp) www.engrcs.com Computer Organization and Microprocessors, V3.0d page 42

MOVFF FSR0L, FSR1L ; copy low-byte MOVFF FSR0H, FSR1H ; copy high-byte MOVF POSTDEC0 ; decrement back to proper address MOVLW 0x94 ; end address 1 CPFSEQ FSR0L ;compare BRA Loop2 ; not equal.. continue ; all done and the 'array' is sorted largest to smallest 7U. Using MPLAB and the following sample Binary Search C code, write equivalent PICmicro assembly code using indirect addressing. /* Search for key in array A and return the location of key: * A[] is a sorted array of elements * imin and imax are limits of search range. */ int binary_search(int A[], int key, int imin, int imax) { // test if array is empty if (imax < imin) // set is empty, so return value showing not found return (-1); // search failed to find the key { // calculate midpoint to cut set in half int imid = midpoint(imin, imax); // three-way comparison if (A[imid] > key) // key is in lower subset return binary_search(a, key, imin, imid-1); if (A[imid] < key) // key is in upper subset return binary_search(a, key, imid+1, imax); // key has been found return imid; 8U. Write a C program that includes a function call, if statement, indirect addressing and a loop. Upon compilation, analyze the.lst file. The analysis should clearly relate the C statements and variables to their equivalent and location in the assembly code. Also, determine the final value assigned to every variable after the program execution. www.engrcs.com Computer Organization and Microprocessors, V3.0d page 43