ECEN : Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University. Homework #2 Solutions

Size: px
Start display at page:

Download "ECEN : Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University. Homework #2 Solutions"

Transcription

1 ECEN : Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University Homework #2 Solutions Upload your homework solution to ecampus as a single file. Your homework solution should include a listing of any C code or Verilog code, along with any output obtained when the code is run. DO NOT upload a zip file. You will have only ONE attempt to upload your homework solution. In addition, your source code (any C code or Verilog code or testbenches) should be sent via to 449and749graders@gmail.com. Your title should state your NAME, SECTION NUMBER and HOMEWORK NUMBER. Name your files in a way that identifies the homework number and the question (e.g. hw1-q1b.v). For all the code that you write, please provide comments for full credit. 1. A and B are two dimensional matrices. Write a C program to add the transpose of matrix A and transpose of matrix B. For both A and B, the size of the matrix will be given along with the entries of the matrix in two input files, ina.txt and inb.txt. The first line of the input file will contain the number of rows followed by the number of columns of the matrix. The entries of the matrix are listed on the next line in row-major order. Print the output matrix C to outc.txt in the same format as input files. Provide comments in your code. Example: If your matrix A is [ ] then ina.txt would be: Run your program on the following pairs of matrices: (a) A = [ ] , B = [ 4.5 ]

2 2 Solutions to Homework #2 (b) A = [ ] 1 1 0, B = [ 2 1 ] Solution. #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { //declaration of variables FILE* fp1; FILE* fp2; FILE *file_ptr_out; int array1_rows, array1_columns, array2_rows, array2_columns; int i = 0, j = 0, loop = 0; float array1[100][100], array2[100][100]; //open input file in read mode fp1 = fopen("ina.txt", "r"); //read from file while (fscanf(fp1, "%f", array1[i])!= EOF) { i++; //open second input file in read mode fp2 = fopen("inb.txt", "r"); while (fscanf(fp2, "%f", array2[j])!= EOF) { j++; //store values of array1 and array row and column dimension array1_rows = array1[0][0]; array2_rows = array2[0][0]; array1_columns = array1[1][0];

3 3 Solutions to Homework #2 array2_columns = array2[1][0]; //Dynamic memory allocation //create an array of pointers dynamically using a double pointer. //input matrix 1 float **matrix1 = (float**)malloc(array1_rows*array1_columns * sizeof(float*)); //transpose of matrix 1 float **transpose_matrix1 = (float**)malloc(array1_rows*array1_columns * sizeof(float*)); //input matrix 2 float **matrix2 = (float**)malloc(array2_rows*array2_columns * sizeof(float*)); //transpose of matrix 2 float **transpose_matrix2 = (float**)malloc(array2_rows*array2_columns * sizeof(float*)); //output sum matrix of the two transpose matrix float **sum_matrix = (float**)malloc(array2_rows*array2_columns * sizeof(float*)); for (i = 0; i < array1_columns; i++) { matrix1[i] = (float*)malloc(array1_columns * sizeof(float)); for (i = 0; i < array1_columns; i++) { transpose_matrix1[i] = (float*)malloc(array1_columns * sizeof(float)); for (i = 0; i < array2_columns; i++) { transpose_matrix2[i] = (float*)malloc(array2_columns * sizeof(float)); for (i = 0; i < array1_columns; i++) { sum_matrix[i] = (float*)malloc(array1_columns * sizeof(int)); for (i = 0; i < array2_columns; i++) { matrix2[i] = (float*)malloc(array2_columns * sizeof(float)); //Assigning values to matrix1 from data read from input file ina.txt for (i = 0; i < array1_rows; i++) { for (j = 0; j < array1_columns; j++) {

4 4 Solutions to Homework #2 matrix1[i][j] = array1[loop + 2][0]; loop++; loop = 0; //Assigning values to matrix2 from data read from input file inb.txt for (i = 0; i < array2_rows; i++) { for (j = 0; j < array2_columns; j++) { matrix2[i][j] = array2[loop + 2][0]; loop++; //Taking transpose of matrix1 and placing output in transpose_matrix1 for (i = 0; i < array1_rows; i++){ for (j = 0; j < array1_columns; j++) { transpose_matrix1[j][i] = matrix1[i][j]; //Taking transpose of matrix2 and placing output in transpose_matrix2 for (i = 0; i < array2_rows; i++) { for (j = 0; j < array2_columns; j++) { transpose_matrix2[j][i] = matrix2[i][j]; //output file OUT.txt in write mode file_ptr_out = fopen("outc.txt", "w"); // fprintf writes onto the corresponding output file fprintf(file_ptr_out, "%d %d\n", array2_columns, array2_rows ); //Calculating the sum of transpose_matrix1 and transpose_matrix2 for (i = 0; i < array1_columns; i++) { for (j = 0; j < array1_rows; j++) {

5 5 Solutions to Homework #2 sum_matrix[i][j] = ((transpose_matrix1[i][j]) + (transpose_matrix2[i][j])); fprintf(file_ptr_out, "%f ", sum_matrix[i][j]); //free dynamically allocated memory free(matrix1); free(matrix2); free(transpose_matrix1); free(transpose_matrix2); free(sum_matrix); //close input and output file pointers fclose(fp1); fclose(fp2); fclose(file_ptr_out); return 0; 2. Construct a Verilog module for a parity generator. It has an 8 bit wide input IN. The output OUT is 1 for even parity else 0. Simulate your parity checker module using a testbench, for the following inputs: (a) (b) (c) Solution. timescale 1ns/1ps module paritygenerator(out, IN); input [7:0] IN; output OUT; ///XORing all the bits of IN gives 1 for odd number of 1 s at the input. //By adding a NOT to that statement meets the requirements of the question. assign OUT = ˆIN[7:0];

6 6 Solutions to Homework #2 module timescale 1ns/1ps module paritygenerator_tb(); //Output wire OUT; // Input reg [7:0]IN; // Instantiation of parity generator module. paritygenerator DUT(.OUT(OUT),.IN(IN)); initial //Set inputs. IN = 8 b ; #20; IN = 8 b ; #20; IN = 8 b ; #20; $finish; module 3. Consider an input clock IN CLK. Also consider an signal IN DAT which is 4 bit wide, arriving at every positive edge of IN CLK. Write Verilog code to generate the following: Output clock OUT CLK and signal OUT DAT which is of 8 bits wide, as shown in the figure below. The OUT DAT signal packs the last 2 values of IN DAT that the system encounters. Test your code for 16 clock cycles, with the input IN DAT = 0000 for first clock cycle, 0001 for the second clock cycle, and so on.

7 7 Solutions to Homework #2 IN_CLK IN_DAT OUT_CLK OUT_DAT XXXXXXXX Waveform for Question 3 Solution. //Verilog Code module packer(out_dat,out_clk,in_dat,in_clk,rst); output [7:0] OUT_DAT; output OUT_CLK; input [3:0] IN_DAT; input IN_CLK; input RST; reg [7:0] OUT_DAT; reg OUT_CLK; reg [7:0] tmp_dat; //generate OUT_CLK IN_CLK or negedge RST) if(rst == 0) OUT_CLK <= 0; else

8 8 Solutions to Homework #2 OUT_CLK <= OUT_CLK; //generate tmp_dat which packs the data at rising edge of IN_CLK IN_CLK or negedge RST) if(rst == 0) tmp_dat <= 0; else if(out_clk == 1) tmp_dat <= else tmp_dat[3:0] <= IN_DAT; {IN_DAT,4 b0000; //latch tmp_dat at posedge of OUT_CLK OUT_CLK or negedge RST) if(rst == 0) OUT_DAT <= 0; else OUT_DAT <= tmp_dat;

9 9 Solutions to Homework #2 module //Testbench module testbench(); reg [3:0] IN_DAT; reg IN_CLK, RST; wire[7:0] OUT_DAT; wire OUT_CLK; packer U0(.OUT_DAT (OUT_DAT),.OUT_CLK (OUT_CLK),.IN_DAT (IN_DAT),.IN_CLK (IN_CLK),.RST (RST) ); initial IN_CLK = 0; //IN_clk of 20MHz always #25 IN_CLK =! IN_CLK; //active low RESET initial RST = 0; #50 RST = 1; //generate IN_DAT from 4 b0000 to 4 b1111 initial IN_DAT <= 4 b0000; #75 IN_DAT <= 4 b0000; #50 IN_DAT <= 4 b0001;

10 10 Solutions to Homework #2 #50 IN_DAT <= 4 b0010; #50 IN_DAT <= 4 b0011; #50 IN_DAT <= 4 b0100; #50 IN_DAT <= 4 b0101; #50 IN_DAT <= 4 b0110; #50 IN_DAT <= 4 b0111; #50 IN_DAT <= 4 b1000; #50 IN_DAT <= 4 b1001; #50 IN_DAT <= 4 b1010; #50 IN_DAT <= 4 b1011; #50 IN_DAT <= 4 b1100; #50 IN_DAT <= 4 b1101; #50 IN_DAT <= 4 b1110; #50 IN_DAT <= 4 b1111; module 4. Read the manual pages on the open() and mmap() function calls. You can either use man open or use the web to find information about these function calls. mmap() allows you to map the file contents to memory address space and then you can write to the memory addresses to write to the file and similarly reading from memory causes data to be read from the file. Write a program using open() and mmap() to create a file containing the string Hello hola how are you. Your program should write to file by writing to memory. Provide comments in your code. Solution. #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <sys/mman.h> #include <string.h> #define FILEPATH "output.bin" //output file name #define NUMBEROFINTS (100) //Number of integers to print to file //size of file created based on NUMBEROFINTS

11 11 Solutions to Homework #2 int main(int argc, char *argv[]) { const char *text = "Hello hola how are you"; size_t textlen = strlen(text); int fp; int result; //used for error checking char *map; //array of ints using mmap() //open file fp= open (FILEPATH,O_RDWR O_CREAT,(mode_t)0600); if (fp == -1) { perror("error opening file for writing"); exit(exit_failure); //resize file to correct length for number ints result=lseek(fp, textlen-1, SEEK_SET); if (result == -1) { //error check close(fp); printf("error in resizing file \n"); exit(1); result = write(fp,"", 1); //write an empty string to file if (result!= 1) { //error check close(fp); printf("error in writing last byte of the file \n"); exit(1); //map file map = mmap(0, textlen, PROT_READ PROT_WRITE, MAP_SHARED, fp, 0); if (map == MAP_FAILED){ //error check close(fp); printf("error in mapping the file \n"); exit(1); //write data to file/mapped array

12 12 Solutions to Homework #2 for (size_t i = 0; i<textlen; i++) { map[i] = text[i]; printf("writing character %c at %zu\n", text[i],i); //unmap the file if (munmap(map, textlen) == -1) { //error check close(fp); printf("error in un-mmapping the file \n"); exit(1); close(fp); //close file return 0; 5. [GRADUATE QUESTION] Write Verilog code to implement a LIFO (Last-In-First-Out) buffer as shown in the figure below. The LIFO buffer can store upto 8 Bytes. The input clock signal is called CLK. The R/W line is used to select between LIFO Read and LIFO Write. When R/W is high, the LIFO performs a read and when R/W is low, the LIFO performs a write. The output FULL line becomes high when the LIFO buffer is or becomes FULL. Similarly, the EMPTY line becomes high when the LIFO buffer is or becomes EMPTY. The signal RST resets the LIFO. Test your code for 16 clock cycles, with DATAIN = for the first clock cycle, for the second clock cycle and so on upto 8 clock cycles. The data is written into LIFO for the first 8 clock cycles. Then perform a Read (R/W = high) for the next 8 clock cycles. Plot waveforms of all the inputs and outputs. DATAIN [7:0] CLK RST R / W LIFO BUFFER DATAOUT[7:0] EMPTY FULL Figure for Question 5

13 13 Solutions to Homework #2 Solution. //Verilog Code module lifo(dataout,empty,full,datain,clk,rst,r_wb); output [7:0] DATAOUT; output EMPTY,FULL; input [7:0] DATAIN; input CLK, RST, R_Wb; reg [7:0] DATAOUT; reg EMPTY, FULL; reg [7:0] lifo_buff [7:0]; //LIFO buffer reg [3:0] ctr; //counter which keeps track of buffer fullness integer i; //if R_Wb is LOW and FULL = 0, input data is written into the buffer and if R_Wb is HIGH and EMPTY = 0 data is read from the buffer CLK or negedge RST) if(rst == 0) for(i=0;i<8;i=i+1) lifo_buff[i] <= 0; ctr <= 4 b0000; else if(r_wb == 0 && FULL == 0) //write to buffer if (ctr < 8) ctr <= ctr + 1; //increment counter since the buffer is empty lifo_buff[ctr-1] <= DATAIN; else if(r_wb == 1 && EMPTY == 0) //read from buffer if(ctr > 0) ctr <= ctr - 1;

14 14 Solutions to Homework #2 DATAOUT <= lifo_buff[ctr-1] ; //EMPTY FLAG = 1 when ctr = 0 and FULL FLAG = 1 when ctr = 7 CLK or negedge RST) if(rst == 0) EMPTY <= 0; else if (ctr == 0) EMPTY <= 1; else EMPTY <= 0; CLK or negedge RST) if(rst == 0) FULL <= 0; else if (ctr == 8) FULL <= 1; else

15 15 Solutions to Homework #2 FULL <= 0; module //Testbench module testbench(); reg [7:0] DATAIN; reg CLK, RST, R_Wb; wire[7:0] DATAOUT; wire EMPTY,FULL; lifo U0(.DATAOUT (DATAOUT),.EMPTY (EMPTY),.FULL (FULL),.DATAIN (DATAIN),.CLK(CLK),.RST (RST),.R_Wb(R_Wb) ); initial CLK = 0; //IN_clk of 20MHz always #25 CLK =! CLK; //active low RESET initial RST = 0; #50 RST = 1;

16 16 Solutions to Homework #2 //generate DATAIN from 8 b to 4 b initial DATAIN <= 8 b ; R_Wb <= 0; #75 DATAIN <= 8 b ; R_Wb <= 0; #50 DATAIN <= 8 b ; R_Wb <= 0; #50 DATAIN <= 8 b ; R_Wb <= 0; #50 DATAIN <= 8 b ; R_Wb <= 0; #50 DATAIN <= 8 b ; R_Wb <= 0; #50 DATAIN <= 8 b ; R_Wb <= 0; #50 DATAIN <= 8 b ; R_Wb <= 0; #50 DATAIN <= 8 b ; R_Wb <= 0; #50 R_Wb <= 1; module

ECEN : Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University. Homework #1 Solutions

ECEN : Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University. Homework #1 Solutions ECEN 449 749: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University Homework #1 Solutions Upload your homework solution to ecampus as a single pdf file. Your

More information

ECEN 449 Microprocessor System Design. Review of C Programming. Texas A&M University

ECEN 449 Microprocessor System Design. Review of C Programming. Texas A&M University ECEN 449 Microprocessor System Design Review of C Programming 1 Objectives of this Lecture Unit Review C programming basics Refresh programming skills 2 Basic C program structure # include main()

More information

ECEN 449 Microprocessor System Design. Review of C Programming

ECEN 449 Microprocessor System Design. Review of C Programming ECEN 449 Microprocessor System Design Review of C Programming 1 Objectives of this Lecture Unit Review C programming basics Refresh es programming g skills s 2 1 Basic C program structure # include

More information

Shared Memory Memory mapped files

Shared Memory Memory mapped files Shared Memory Memory mapped files 1 Shared Memory Introduction Creating a Shared Memory Segment Shared Memory Control Shared Memory Operations Using a File as Shared Memory 2 Introduction Shared memory

More information

In this lecture, we will focus on two very important digital building blocks: counters which can either count events or keep time information, and

In this lecture, we will focus on two very important digital building blocks: counters which can either count events or keep time information, and In this lecture, we will focus on two very important digital building blocks: counters which can either count events or keep time information, and shift registers, which is most useful in conversion between

More information

Modeling Sequential Circuits in Verilog

Modeling Sequential Circuits in Verilog Modeling Sequential Circuits in Verilog COE 202 Digital Logic Design Dr. Muhamed Mudawar King Fahd University of Petroleum and Minerals Presentation Outline Modeling Latches and Flip-Flops Blocking versus

More information

Operating systems. Lecture 9

Operating systems. Lecture 9 Operating systems. Lecture 9 Michał Goliński 2018-11-27 Introduction Recall Reading and writing wiles in the C/C++ standard libraries System calls managing processes (fork, exec etc.) Plan for today fork

More information

Lab 7 (All Sections) Prelab: Introduction to Verilog

Lab 7 (All Sections) Prelab: Introduction to Verilog Lab 7 (All Sections) Prelab: Introduction to Verilog Name: Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work 1 Objective The

More information

ECE 650 Systems Programming & Engineering. Spring 2018

ECE 650 Systems Programming & Engineering. Spring 2018 ECE 650 Systems Programming & Engineering Spring 2018 Inter-process Communication (IPC) Tyler Bletsch Duke University Slides are adapted from Brian Rogers (Duke) Recall Process vs. Thread A process is

More information

Dynamic memory allocation

Dynamic memory allocation Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes

More information

Why files? 1. Storing a large amount of data 2. Long-term data retention 3. Access to the various processes in parallel

Why files? 1. Storing a large amount of data 2. Long-term data retention 3. Access to the various processes in parallel 1 File System Why files? 1. Storing a large amount of data 2. Long-term data retention 3. Access to the various processes in parallel 2 Basic Terms File Structures Field basic unit of data. Contains single

More information

Page rank computation HPC course project a.y Compute efficient and scalable Pagerank

Page rank computation HPC course project a.y Compute efficient and scalable Pagerank Page rank computation HPC course project a.y. 2012-13 Compute efficient and scalable Pagerank 1 PageRank PageRank is a link analysis algorithm, named after Brin & Page [1], and used by the Google Internet

More information

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

CSC209H Lecture 3. Dan Zingaro. January 21, 2015 CSC209H Lecture 3 Dan Zingaro January 21, 2015 Streams (King 22.1) Stream: source of input or destination for output We access a stream through a file pointer (FILE *) Three streams are available without

More information

Workshop on Digital Circuit Design in FPGA

Workshop on Digital Circuit Design in FPGA Organized by: Dept. of EEE Workshop on Digital Circuit Design in FPGA Presented By Mohammed Abdul Kader Assistant Professor, Dept. of EEE, IIUC Email:kader05cuet@gmail.com Website: kader05cuet.wordpress.com

More information

25.2 Opening and Closing a File

25.2 Opening and Closing a File Lecture 32 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 32: Dynamically Allocated Arrays 26-Nov-2018 Location: Chemistry 125 Time: 12:35 13:25 Instructor:

More information

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes

More information

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430 Week 2 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430 1 Why is the Shell Important? Shells provide us with a way to interact with the core system Executes programs on

More information

ESC101N: Fundamentals of Computing End-sem st semester

ESC101N: Fundamentals of Computing End-sem st semester ESC101N: Fundamentals of Computing End-sem 2010-11 1st semester Instructor: Arnab Bhattacharya 8:00-11:00am, 15th November, 2010 Instructions 1. Please write your name, roll number and section below. 2.

More information

Programming & Data Structure

Programming & Data Structure File Handling Programming & Data Structure CS 11002 Partha Bhowmick http://cse.iitkgp.ac.in/ pb CSE Department IIT Kharagpur Spring 2012-2013 File File Handling File R&W argc & argv (1) A file is a named

More information

Content. In this chapter, you will learn:

Content. In this chapter, you will learn: ARRAYS & HEAP Content In this chapter, you will learn: To introduce the array data structure To understand the use of arrays To understand how to define an array, initialize an array and refer to individual

More information

Today s Learning Objectives

Today s Learning Objectives Today s Learning Objectives 15-123 Systems Skills in C and Unix We will Review ints and modular arithmetic Learn basic Data types and Formats How Conditionals and loops work How Arrays are defined, accessed,

More information

NISC Technology Online Toolset

NISC Technology Online Toolset NISC Technology Online Toolset Mehrdad Reshadi, Bita Gorjiara, Daniel Gajski Technical Report CECS-05-19 December 2005 Center for Embedded Computer Systems University of California Irvine Irvine, CA 92697-3425,

More information

Unit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character

Unit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character 1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard

More information

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE I A.A. 2017/2018 PROGRAMMAZIONE I A.A. 2017/2018 INPUT/OUTPUT INPUT AND OUTPUT Programs must be able to write data to files or to physical output devices such as displays or printers, and to read in data from files or

More information

Course Topics - Outline

Course Topics - Outline Course Topics - Outline Lecture 1 - Introduction Lecture 2 - Lexical conventions Lecture 3 - Data types Lecture 4 - Operators Lecture 5 - Behavioral modeling A Lecture 6 Behavioral modeling B Lecture 7

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 9 Pointer Department of Computer Engineering 1/46 Outline Defining and using Pointers

More information

F28HS2 Hardware-Software Interface. Lecture 3 - Programming in C 3

F28HS2 Hardware-Software Interface. Lecture 3 - Programming in C 3 F28HS2 Hardware-Software Interface Lecture 3 - Programming in C 3 Low level programming in C want to control hardware devices devices mapped into memory accessed at specific memory addresses set memory

More information

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C 2017-03-06 Processes often need to communicate CSCB09: Software Tools and Systems Programming E.g. consider a shell pipeline: ps wc l ps needs to send its output to wc E.g. the different worker processes

More information

ECEN 468 Advanced Logic Design

ECEN 468 Advanced Logic Design ECEN 468 Advanced Logic Design Lecture 28: Synthesis of Language Constructs Synthesis of Nets v An explicitly declared net may be eliminated in synthesis v Primary input and output (ports) are always retained

More information

File I/O. Arash Rafiey. November 7, 2017

File I/O. Arash Rafiey. November 7, 2017 November 7, 2017 Files File is a place on disk where a group of related data is stored. Files File is a place on disk where a group of related data is stored. C provides various functions to handle files

More information

Lab 7 (Sections 300, 301 and 302) Prelab: Introduction to Verilog

Lab 7 (Sections 300, 301 and 302) Prelab: Introduction to Verilog Lab 7 (Sections 300, 301 and 302) Prelab: Introduction to Verilog Name: Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work

More information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) Class Teacher: Pralay Mitra Department of Computer Science and Engineering Indian Institute of Technology Kharagpur A complete C program

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 6

Darshan Institute of Engineering & Technology for Diploma Studies Unit 6 1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard

More information

MMAP AND PIPE. UNIX Programming 2015 Fall by Euiseong Seo

MMAP AND PIPE. UNIX Programming 2015 Fall by Euiseong Seo MMAP AND PIPE UNIX Programming 2015 Fall by Euiseong Seo Memory Mapping mmap(2) system call allows mapping of a file into process address space Instead of using read() and write(), just write to memory

More information

Verilog HDL: Behavioral Counter

Verilog HDL: Behavioral Counter Verilog HDL: Behavioral Counter This example describes an 8-bit loadable counter with count enable. The always construct, highlighted in red text, describes how the counter should behave. behav_counter.v

More information

Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics

More information

Chapter 10. The UNIX System Interface

Chapter 10. The UNIX System Interface 프로그래밍 1 1 Chapter 10. The UNIX System Interface June, 2016 Dept. of software Dankook University http://embedded.dankook.ac.kr/~baeksj 파일의개념 (1/5) 2 파일의정의 사용자가이용할수있는데이터의실체레코드들의집합이라고정의 파일의필요성 데이터의효율적인저장및검색을위해파일단위구분

More information

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Adapted from the slides Revisões sobre Programação em C, Sérgio Crisóstomo Compilation #include int main()

More information

Operating System Labs. Yuanbin Wu

Operating System Labs. Yuanbin Wu Operating System Labs Yuanbin Wu cs@ecnu Annoucement Next Monday (28 Sept): We will have a lecture @ 4-302, 15:00-16:30 DON'T GO TO THE LABORATORY BUILDING! TA email update: ecnucchuang@163.com ecnucchuang@126.com

More information

2009 S2 COMP File Operations

2009 S2 COMP File Operations 2009 S2 COMP1921 9. File Operations Oliver Diessel odiessel@cse.unsw.edu.au Last updated: 16:00 22 Sep 2009 9. File Operations Topics to be covered: Streams Text file operations Binary file operations

More information

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ. C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,

More information

Arrays and Pointers in C. Alan L. Cox

Arrays and Pointers in C. Alan L. Cox Arrays and Pointers in C Alan L. Cox alc@rice.edu Objectives Be able to use arrays, pointers, and strings in C programs Be able to explain the representation of these data types at the machine level, including

More information

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017 Pointers (part 1) EECS 2031 25 September 2017 1 What are pointers? We have seen pointers before. scanf( %f, &inches );! 2 1 Example char c; c = getchar(); printf( %c, c); char c; char *p; c = getchar();

More information

Computer Programming Unit 3

Computer Programming Unit 3 POINTERS INTRODUCTION Pointers are important in c-language. Some tasks are performed more easily with pointers such as dynamic memory allocation, cannot be performed without using pointers. So it s very

More information

High Performance Programming Programming in C part 1

High Performance Programming Programming in C part 1 High Performance Programming Programming in C part 1 Anastasia Kruchinina Uppsala University, Sweden April 18, 2017 HPP 1 / 53 C is designed on a way to provide a full control of the computer. C is the

More information

Discussion Session 6. CS/ECE 552 Ramkumar Ravi 05 Mar 2012

Discussion Session 6. CS/ECE 552 Ramkumar Ravi 05 Mar 2012 Discussion Session 6 CS/ECE 552 Ramkumar Ravi 05 Mar 2012 CS/ECE 552, Spring 2012 Introduction Rules for HW are up-> Please follow instructions HW3 is due on 03/07 EXPLORING FIFO MIDTERM REVIEW 03/06,

More information

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut mith College CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 2 Hours D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to Assembly Unix Standard

More information

Organization of a file

Organization of a file File Handling 1 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example: Consider keeping students records 100 students

More information

APS105. Malloc and 2D Arrays. Textbook Chapters 6.4, Datatype Size

APS105. Malloc and 2D Arrays. Textbook Chapters 6.4, Datatype Size APS105 Malloc and 2D Arrays Textbook Chapters 6.4, 10.2 Datatype Size Datatypes have varying size: char: 1B int: 4B double: 8B int sizeof(): a builtin function that returns size of a type int x =

More information

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Comp 541 Digital Logic and Computer Design Fall 2014 Lab #4: Sequential Design: Counters Issued Wed 9/10/14; Due Wed 9/17/14 (11:59pm) This lab assignment

More information

Lecture 7: Files. opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments

Lecture 7: Files. opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments Lecture 7: Files opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments Lecture 5: Files, I/O 0IGXYVI*MPIW 0 opening/closing files reading/writing

More information

mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut

mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut dthiebaut@smithedu Outline A Few Words about HW 8 Finish the Input Port Lab! Revisiting Homework

More information

Chapter-5. EE 335 : Advanced Microprocessor. Logic Design with Behavioral Models of Combinational and Sequential Logic

Chapter-5. EE 335 : Advanced Microprocessor. Logic Design with Behavioral Models of Combinational and Sequential Logic EE 335 : Advanced Microprocessor Chapter-5 Logic Design with Behavioral Models of Combinational and Sequential Logic Ajay Kumar Yadav (Instructor) Electrical & Computer Engineering Temple University Data

More information

EM108 Software Development for Engineers

EM108 Software Development for Engineers EE108 Section 4 Files page 1 of 14 EM108 Software Development for Engineers Section 4 - Files 1) Introduction 2) Operations with Files 3) Opening Files 4) Input/Output Operations 5) Other Operations 6)

More information

CSE 124 Discussion (10/3) C/C++ Basics

CSE 124 Discussion (10/3) C/C++ Basics CSE 124 Discussion (10/3) C/C++ Basics Topics - main() function - Compiling with gcc/makefile - Primitives - Structs/Enums - Function calls/loops - C++ Classes/stdtl - Pointers/Arrays - Memory allocation/freeing

More information

COSC Operating Systems Design, Fall Lecture Note: Unnamed Pipe and Shared Memory. Unnamed Pipes

COSC Operating Systems Design, Fall Lecture Note: Unnamed Pipe and Shared Memory. Unnamed Pipes COSC4740-01 Operating Systems Design, Fall 2001 Lecture Note: Unnamed Pipe and Shared Memory Unnamed Pipes Pipes are a form of Inter-Process Communication (IPC) implemented on Unix and Linux variants.

More information

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee. Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem

More information

Files. Eric McCreath

Files. Eric McCreath Files Eric McCreath 2 What is a file? Information used by a computer system may be stored on a variety of storage mediums (magnetic disks, magnetic tapes, optical disks, flash disks etc). However, as a

More information

Hard/Software Interface MicroEnable

Hard/Software Interface MicroEnable Appix A Hard/Software Interface MicroEnable A.1 Register/DMA on Demand Transfer, C example #include #include"menable.h" int main(int argc, char** argv) { microenable* board; fpga_design* design;

More information

Digital design laboratory 5

Digital design laboratory 5 Digital design laboratory 5 Preparations Launch the ISE Design Suite Create new project: File -> New Project Preparations Name: DigLab5 Location: D drive! D:\DigLab5 Working directory: The same as Location

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

Digital Design Using Verilog EE Midterm Examination

Digital Design Using Verilog EE Midterm Examination Name Solution Digital Design Using Verilog EE 4702-1 Midterm Examination 5 April 2000 8:40-9:30 CDT Alias always @( posedge ) Problem 1 Problem 2 Exam Total (40 pts) (60 pts) (100 pts) Good Luck! Problem

More information

File Descriptors and Piping

File Descriptors and Piping File Descriptors and Piping CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 8 Today s topics File Descriptors

More information

Introduction to Verilog and ModelSim. (Part 5 Sequential Logic)

Introduction to Verilog and ModelSim. (Part 5 Sequential Logic) Introduction to Verilog and ModelSim (Part 5 Sequential Logic) Sequential Logic It implements storage capabilities of the system Data latch structure Requires clock/gate/latch signal input Latch (level

More information

A short introduction to SystemVerilog. For those who know VHDL We aim for synthesis

A short introduction to SystemVerilog. For those who know VHDL We aim for synthesis A short introduction to SystemVerilog For those who know VHDL We aim for synthesis 1 Verilog & SystemVerilog 1984 Verilog invented, C-like syntax First standard Verilog 95 Extra features Verilog 2001 A

More information

TCSS 422: OPERATING SYSTEMS

TCSS 422: OPERATING SYSTEMS TCSS 422: OPERATING SYSTEMS fork() Process API, Limited Direct Execution Wes J. Lloyd Institute of Technology University of Washington - Tacoma Creates a new process - think of a fork in the road Parent

More information

Pointers and File Handling

Pointers and File Handling 1 Pointers and File Handling From variables to their addresses Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 2 Basics of Pointers INDIAN INSTITUTE OF TECHNOLOGY

More information

VHDL/Verilog Simulation. Testbench Design

VHDL/Verilog Simulation. Testbench Design VHDL/Verilog Simulation Testbench Design The Test Bench Concept Elements of a VHDL/Verilog testbench Unit Under Test (UUT) or Device Under Test (DUT) instantiate one or more UUT s Stimulus of UUT inputs

More information

mith College Computer Science CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut

mith College Computer Science CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut mith College CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 4 Hours! D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to

More information

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be

More information

Implementation of Pipe under C in Linux. Tushar B. Kute,

Implementation of Pipe under C in Linux. Tushar B. Kute, Implementation of Pipe under C in Linux Tushar B. Kute, http://tusharkute.com Pipe We use the term pipe to mean connecting a data flow from one process to another. Generally you attach, or pipe, the output

More information

Arrays and Pointers. CSE 2031 Fall November 11, 2013

Arrays and Pointers. CSE 2031 Fall November 11, 2013 Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example

More information

Fundamentals of Programming. Lecture 10 Hamed Rasifard

Fundamentals of Programming. Lecture 10 Hamed Rasifard Fundamentals of Programming Lecture 10 Hamed Rasifard 1 Outline File Input/Output 2 Streams and Files The C I/O system supplies a consistent interface to the programmer independent of the actual device

More information

File Handling. Reference:

File Handling. Reference: File Handling Reference: http://www.tutorialspoint.com/c_standard_library/ Array argument return int * getrandom( ) static int r[10]; int i; /* set the seed */ srand( (unsigned)time( NULL ) ); for ( i

More information

Memory Allocation in C

Memory Allocation in C Memory Allocation in C When a C program is loaded into memory, it is organized into three areas of memory, called segments: the text segment, stack segment and heap segment. The text segment (also called

More information

Engineering program development 6. Edited by Péter Vass

Engineering program development 6. Edited by Péter Vass Engineering program development 6 Edited by Péter Vass Variables When we define a variable with its identifier (name) and type in the source code, it will result the reservation of some memory space for

More information

Department of Computer Science and Electrical Engineering. CMPE 415 Verilog Events Timing and Testbenches Prof. Ryan Robucci

Department of Computer Science and Electrical Engineering. CMPE 415 Verilog Events Timing and Testbenches Prof. Ryan Robucci Department of Computer Science and Electrical Engineering CMPE 415 Verilog Events Timing and Testbenches Prof. Ryan Robucci An Event Driven Language also used for Synthesis We emphasize use of Verilog

More information

int marks[10]; // fixed size and fixed address No change in Memory address.

int marks[10]; // fixed size and fixed address No change in Memory address. Dynamic Memory Allocation : Used When we want to allocate memory during run time. int marks[10]; // fixed size and fixed address No change in Memory address. // fixed size. ( no change in size possible

More information

File Handling. 21 July 2009 Programming and Data Structure 1

File Handling. 21 July 2009 Programming and Data Structure 1 File Handling 21 July 2009 Programming and Data Structure 1 File handling in C In C we use FILE * to represent a pointer to a file. fopen is used to open a file. It returns the special value NULL to indicate

More information

8/26/2010. Introduction to 8085 BLOCK DIAGRAM OF INTEL Introduction to Introduction to Three Units of 8085

8/26/2010. Introduction to 8085 BLOCK DIAGRAM OF INTEL Introduction to Introduction to Three Units of 8085 BLOCK DIAGRAM OF INTEL 8085 GURSHARAN SINGH TATLA Introduction to 8085 It was introduced in 1977. It is 8-bit microprocessor. Its actual name is 8085 A. It is single NMOS device. It contains 6200 transistors

More information

CP2 Revision. theme: file access and unix programs

CP2 Revision. theme: file access and unix programs CP2 Revision theme: file access and unix programs file access in C basic access functionality: FILE *fopen(const char *filename, const char *mode); This function returns a pointer to a file stream (or

More information

C-Refresher: Session 10 Disk IO

C-Refresher: Session 10 Disk IO C-Refresher: Session 10 Disk IO Arif Butt Summer 2017 I am Thankful to my student Muhammad Zubair bcsf14m029@pucit.edu.pk for preparation of these slides in accordance with my video lectures at http://www.arifbutt.me/category/c-behind-the-curtain/

More information

LZSS Circuit By Eliat Avidan CPE 405

LZSS Circuit By Eliat Avidan CPE 405 LZSS Circuit By Eliat Avidan CPE 405 LZSS is one of many techniques of decoding and encoding losslessly. This is a simple compression technique that based on two windows: search buffer and lookahead buffer.

More information

12-Dec-11. Gursharan Singh Maninder Kaur. Introduction to 8085 BLOCK DIAGRAM OF INTEL Introduction to Introduction to 8085

12-Dec-11. Gursharan Singh Maninder Kaur. Introduction to 8085 BLOCK DIAGRAM OF INTEL Introduction to Introduction to 8085 mailme@gursharansingh.in BLOCK DIAGRAM OF INTEL 8085 mailme@maninderkaur.in Introduction to 8085 It was introduced in 1977. It is 8-bit microprocessor. Its actual name is 8085 A. It is single NMOS device.

More information

Personal SE. Functions, Arrays, Strings & Command Line Arguments

Personal SE. Functions, Arrays, Strings & Command Line Arguments Personal SE Functions, Arrays, Strings & Command Line Arguments Functions in C Syntax like Java methods but w/o public, abstract, etc. As in Java, all arguments (well, most arguments) are passed by value.

More information

C programming basics T3-1 -

C programming basics T3-1 - C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of

More information

POSIX Shared Memory. Linux/UNIX IPC Programming. Outline. Michael Kerrisk, man7.org c 2017 November 2017

POSIX Shared Memory. Linux/UNIX IPC Programming. Outline. Michael Kerrisk, man7.org c 2017 November 2017 Linux/UNIX IPC Programming POSIX Shared Memory Michael Kerrisk, man7.org c 2017 mtk@man7.org November 2017 Outline 10 POSIX Shared Memory 10-1 10.1 Overview 10-3 10.2 Creating and opening shared memory

More information

Answer all questions. Write your answers only in the space provided. Full marks = 50

Answer all questions. Write your answers only in the space provided. Full marks = 50 Answer all questions. Write your answers only in the space provided. Full marks = 50 1. Answer the following: [2+3+2+1=8 marks] a) What are the minimum and maximum numbers that can be represented in 10-bit

More information

Arrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.

Arrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014. Arrays Arrays and Pointers l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. EECS 2031 Fall 2014 November 11, 2013 1 2 Arrays: Example

More information

Preview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall

Preview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall Preview Process Control What is process? Process identifier The fork() System Call File Sharing Race Condition COSC350 System Software, Fall 2015 1 Von Neumann Computer Architecture: An integrated set

More information

Input/Output. Input/Output and Files. Input/Output. I/O System Objectives

Input/Output. Input/Output and Files. Input/Output. I/O System Objectives Input/Output and Files slide 1 Input/Output slide 2 background reading to support this material can be found in Ritchie Chapter 8 Silberschatz 13.3, 11.1 and 11.6 I/O Characteristics range of characteristics/performance

More information

Understanding Pointers

Understanding Pointers Division of Mathematics and Computer Science Maryville College Pointers and Addresses Memory is organized into a big array. Every data item occupies one or more cells. A pointer stores an address. A pointer

More information

Homework 5. Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100

Homework 5. Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100 Homework 5 Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100 UNIX System 1. (10 points) I want to make the file libprog.a in my home directory available to everyone so

More information

CSE 591: Advanced Hardware Design and Verification (2012 Spring) LAB #0

CSE 591: Advanced Hardware Design and Verification (2012 Spring) LAB #0 Lab 0: Tutorial on Xilinx Project Navigator & ALDEC s Active-HDL Simulator CSE 591: Advanced Hardware Design and Verification Assigned: 01/05/2011 Due: 01/19/2011 Table of Contents 1 Overview... 2 1.1

More information

MODULE 5: Pointers, Preprocessor Directives and Data Structures

MODULE 5: Pointers, Preprocessor Directives and Data Structures MODULE 5: Pointers, Preprocessor Directives and Data Structures 1. What is pointer? Explain with an example program. Solution: Pointer is a variable which contains the address of another variable. Two

More information

CSI 402 Lecture 2 Working with Files (Text and Binary)

CSI 402 Lecture 2 Working with Files (Text and Binary) CSI 402 Lecture 2 Working with Files (Text and Binary) 1 / 30 AQuickReviewofStandardI/O Recall that #include allows use of printf and scanf functions Example: int i; scanf("%d", &i); printf("value

More information

5.14 Algorithmic State Machine (ASM) Charts

5.14 Algorithmic State Machine (ASM) Charts 5.4 Algorithmic State Machine (ASM) Charts An ASM chart is an alternative method for describing a state machine More directly shows the sequential steps of a state machine. Easier to understand input priority

More information

Nikhil Gupta. FPGA Challenge Takneek 2012

Nikhil Gupta. FPGA Challenge Takneek 2012 Nikhil Gupta FPGA Challenge Takneek 2012 RECAP FPGA Field Programmable Gate Array Matrix of logic gates Can be configured in any way by the user Codes for FPGA are executed in parallel Configured using

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:

More information

An Example Application for the TMU Package

An Example Application for the TMU Package An Example Application for the TMU Package Dave Galloway Edward S. Rogers Sr. Department of Electrical and Computer Engineering University of Toronto April 2013 Introduction This document describes a simple

More information