Archive

Archive for the ‘Technology’ Category

Differences between TCP & UDP

January 10th, 2012 No comments

TCP vs UDP

Major differences between the TCP(Transmission Control) & UDP(User Datagram) transport layer protocols:

TCP UDP
Stream-Oriented : Data transmitted as a virtual stream of bytes Message-Oriented : Data transmitted as individual data packets called datagrams(the basic unit of data transferred)
Reorders packets Does not reorder packets; leaves it to the application layer
Data Reliability:Absolute guarantee that data remains intact No guarantee; No data reliability
Two-way connection reliable One-way connection reliable
Uses a 20 bytes header Uses a 8 bytes header
Error checking No error checking
Flow control No flow control
Slower speed (due to the above) Faster than TCP
Used when speed is not critical Used in games and applications where speed(time) is critical
Examples include SMTP, HTTP, FTP, Telnet, etc Examples include DNS, TFTP, RIP, VoIP, SNMP, etc

Fundamentals Of Computer Networks

September 9th, 2011 3 comments

How it all started - The APRANET

Imagine(if possible), a time without the world wide web. (and without the internet, if you know the difference). Consider a college (let's call it A) in a university which has the engineering disciplines ECE & MAE (the old GBPEC) but does not have CSE. If a person from college A wants to learn about microprocessors, he can easily access notes from a computer in college A's network. Another college B has the CSE branch. This student from A wants to learn a programming language using course material on B's computers. So, How does he access B's network?

internet

If we connect the two networks of the colleges A & B, we get what is called an internetwork or internet. Imagine the internet as a simple wire that connects two nodes. in this case, the nodes are two individual networks.

Now consider creating an internet of all the colleges in the universities or perhaps, of various universities by joining their networks using a wire. The same idea was implemented by four institutions - UCSB, SRI, UTAH, & UCLA. This was the first internet - which was called the APRANET. It expanded to cover the whole globe - and formed what is called the World Wide Web. So, the world wide web is an instance of, and perhaps the largest instance of an internet. But it is not the same thing as the internet.


How it all works - The TCP/IP Model

We will continue to think of the internet (now used for the www) as a wire. And the world wide web as a big wire. Many machines are connected to this wire. These may be Computers, Mobiles & Servers. Servers are big machines that store all the websites (data+pages+audio+images+video) you visit. These are connected directly to the internet. Your desktops & latops and mobiles are connected to this wire (internet) indirectly, via an ISP (your Internet Service Provider - MTNL?)

internet_servers

Now, all that happens on the wire is exchange of data packets - from you to zarrata.com's server (upload) and from zarrata.com's server to you (download) - When you're viewing this page, you've received some data packet from the server which are temporarily stored on your computer. For example, the contents of this page including the text and images.

How these packets are and created, sent & received is defined by protocols as per the TCP/IP model. There are various layers of abstraction involved in the process (Physical & Data Link, Network, Transport & Application) but as of now, we only need to worry about the Application Layer. That is, how the user is interfaced to the network. It is more about why you see what you see on the internet and not about how the internet breaks down and integrates the data packets.

And by the way, you (and zarrata.com) are not the only ones on the internet. So, how does the internet know which two machines have to be connected (ie-interchange data packets)? Two things - IP addresses & Routing. The data packets have to be addressed to a particular machine (server or your desktop).


IP Addresses, DNS & Subnets

Just like each place in the world has an address - Each machine on the internet has an address called the IP Address. For instance, your computer has an IP address, the server that hosts this website has an IP adress, and so on. And when we use "www.zarrata.com", we are actually referring to IP address "69.147.225.58" which is assigned to zarrata.com. You can find your own IP at http://whatismyipaddress.com/ & a website's (server's) ip at http://www.yougetsignal.com/tools/web-sites-on-web-server/

Then, of course, we would need a database that has all the IP's corresponding to all the websites on the internet. It could then be used to translate the human-friendly address or domain names(zarrata.com) to the real(IP) address(64.197.225.58). This database is called the DNS (Domain Name System).

Now, an IP address is actually used in binary for communication by the computer. For instance, 216.27.61.137 translates to 11011000.00011011.00111101.10001001 - each number is represented by 8 positions in binary form - and are hence, called octets. The complete IP address is then a 32-bit number (made from 4 octets). Each of these 32 bits can be either 0 or 1 - thus allowing 2^(32) unique IP addresses which is about 4.3 billion possibilities.
[PS - The IP address considered here is the most prevalent version of the IP address - called IPv4. The other being IPv6]

ip_address_v4

Now, the first half of the IP address - the first 2 octets - 216.27 is the network part and the second half - the last 2 octects 61.137 form the machine or host part. ie-the first half is the neighborhood or street where you live and the second half is the exact house in the neighborhood. Hence, machines having the same first half of the IP belong to the same network. For instace, 129.144.50.56 & 129.144.23.122 belong to the same network.

Subnets & Subnetting

Networks having a large number of hosts are divided into subnetworks or subnets. A subnet number is assigned to each subnet. The second half or host part now has the host and the subnet number combined together - using the AND operation.

Consider a large network 192.168.10.0 that has the IP addresses ranging from 192.168.10.1 - 192.168.10.224

(225 is the maximum value of any octet - since, 256 is not an octect; 256 = 100000000. Here 224 is used since 192.168.10.255 is a BROADCAST ADDRESS and cannot be used).

Now, we wish to divide the network into two subnetworks:
The first network consisting of the machines 192.168.10.1 - 192.168.10.127
The second network consisting of the machines 192.168.10.128 - 192.168.10.225

It is done by using a subnet mask which is defined by :
1)The class of IP(see table below) - here, the mask to be used is 255.255.255.0
2)The address that divided the network - here, 192.168.10.128

Hence, the mask obtained from 1) & 2) is 255.255.255.128

Class Address Range Subnet Mask
Class A 1.xxx.xxx.xxx - 126.xxx.xxx.xxx 255.0.0.0
Class B 128.xxx.xxx.xxx - 191.xxx.xxx.xxx 255.255.0.0
Class C 192.xxx.xxx.xxx - 223.xxx.xxx.xxx 255.225.225.0
Class D 224.xxx.xxx.xxx - 239.xxx.xxx.xxx Reserved for multicast groups
Class E 240.xxx.xxx.xxx - 254.xxx.xxx.xxx Reserved for future use, research & development

[Note - 127.x.x.x addresses are reserved for loopback or localhost]


How email works - The SMTP, POP & IMAP Protocols

There are two protocols involved when you email someone (did you know or care?). One for sending the mail - called the SMTP (Simple Mail Transfer) & another for receiving the mail - could be either POP or IMAP. POP is simpler & the most common one. IMAP is hierarchy based and less common.

Suppose you send a mail to your girlfriend, this is what really happens -

email

Steps Involved in sending an email (when someone sends me a mail at devrishabh@gmail.com)

Step 1- SMTP of sender breaks the id into two parts - devrishabh & gmail.com(it is interested only in the latter)
Step 2 - SMTP of sender gets the IP of the SMTP server for gmail.com (receiver, me)
Step 3 - With this IP, it connects to the SMTP Of gmail.com using port 25 and gives it the message. (don't worry about that)
Step 4 - Gmail uses POP3 to put the message in my inbox. Totally.


How I upload files to zarrata.com - The FTP

Now, how do people who have websites - or a server upload files to their servers? If you try searching google from a free songs using the intitle:"index of" prefix, you'll come across a file hierarchy. This is how files are arranged on the server. When you open a website. The DNS first maps the website to it's IP address (of the server) and it then loads the index.html or index.php file from the server which is essentially what you call the "HOME PAGE" of the website. This is the page that loads first (just like the main function is executed first in a C program, YEAH!)

All other files are somehow linked to the index.html using html code. (which is the code that http understands). your browser is like a compiler+executor of this code. It takes this code an the input and produces the website that you see as the output. You can View Source of this page to see what i'm talking about.

Now, how are all these HTML (for now) files uploaded to the server? - using the FTP or File Transmission Protocol. We (the webmasters, aha) have a ftp client wherein we need to login with our ftp details and upload files. Easy. You can try replacing http:// by ftp:// on a webpage. For instance, try ftp://zarrata.com/durofy instead of http://zarrata.com/durofy & see what you get.

Don't worry if you don't have the login details. here's a sneak into my ftp client -

You can see the desktop and the remove site (the server for zarrata.com). Files can then be transferred between these two using this client.


Logging on to the Remote Computer - TELNET

If you want to do more than just transfer files, you can even log on to a computer that is located in a remote location (away from you) using your desktop. This is done using a telecommunication network or TELNET. It has now evolved to something called SSH or Secure Shell which is a combination of TELNET + Encryption for security.


How Google Works - Internet Search

First, If you think Google searches the internet, well, it just does'nt. It searches only a copy of the internet (whatever it has of it) stored in a database on it's own server. There are three steps involved - CRAWLING + INDEXING + RANKING.

CRAWLING - Google creates these algorithms or programs called spiders (or bots or robots or crawlers) that crawl the web and look for links. They go on a page (where they've arrived from another page). Then they add that page to a queue for indexing. They then click on the links on that page. Then, links on the new pages & so on. ((until they reach a page where there are no new links or the new ones are already in google's index) This allows google to index thousands of pages in one go.

INDEXING & RANKING - All the links in the queue are indexed and ranked. Ranking a page involves a number of questions (200+ according to Matt Cutts - developer of Google Social Search - the one who allowed you to put a family filter and let you search for soft porn).

Some on the questions are -
(ie-If someone search for a keyword, what websites will be indexed?)

  • How many times does the page contain the keywords?
  • Are these keywords in the page title?
  • Is the page from a quality website (determined by Google's Page Rank - you don't need to worry about that)
  • Does the page include synonyms for these words.

How do we make websites - HTML


Forums & Boards before the World Wide Web - USENET

Before the world wide web (& before the internet - now you know the difference) - we had newsgroups instead of forums. Just like Apranet, various colleges connected together to create a network for news exchange. This was called the USENET.

Google groups still has the most comprehensive archive of Usenet postings (back to 1981).

How USENET Works -

Step 1 - There is a newsreader that connects to a news server.
Step 2 - It downloads all new messages posted in groups you're subscribed to.
Step 3 - When you reply, the reply is stored in the server
Step 4 - News server connects to other servers and updates the message.
Step 5 - Changes are replicated until all the servers are updated.


Forms & Programs on the internet - CGI

Are you a programmer? What if you want to write code and execute it as a web page and publish it as a website. Forms is a good example.(it is a program - a collection of inputs and outputs) This is done using CGI or Common Gateway Interface.

CGI is not a programming language itself but it is like a program that can be written in many languages. A file written in C, Perl, JAVA, etc can be run as a website by including a html header in the print function of the program and then uploading it to the server with the extention .cgi

Sample Code for CGI in C:

#include
int main (void)
{
printf("content_type: text/plan; charset=us_ascii\n");
printf("Hellow !\n");
return 0;
}


Mobile Computing - Personal Communication Services (PCS)

September 6th, 2011 No comments

1) Overview

mobile_computing_pcs


  • PCS (Personal Communication Services) is a general term for a variety of voice, data & multimedia services. (GSM is a kind of PCS system)
  • Such a Personal Communication Service can be accessed at any time, place or form (They are mobile/portable/ubiquitous).
  • PCS lays the foundation architecture. GSM & GPRS build upon & extend the PCS architecture to achieve new functionality.

2) Architecture

pcs_architecture

(MS-Mobile Station, BS-Base Station, MSC-Mobile Switching Center)


3) Cellular Telephony

AMPS (analog) - Advanced Mobile Phone System
DAMPS - Digital AMPS

pcs_cellular_telephony_networks

4) Mobility Management

  • It is a measure of the performance of the PCS system.
  • Uses the database registers HLR & VLR for home & visitor location respectively.

Handoff - when you switch between two Base Stations but you are in the same area(say, within Delhi).

If the old and new Base Stations are a part of the same MSC, it is called inter-BS or Inter-cell.
If the old & new BS are from different MSC's, it is inter-system or inter-MSC handoff.

Methods of Handoff Detection :

MCHO - MS monitors signal from BS continuously & initiates handoff when criteria is met.
MAHO - MS monitors signal when asked to do so by the network.
NCHO - BS monitors signal from MS.


Roaming- When you move from one area to another.(say, from Delhi to Harayana).

a) Registration Steps:

  • VLR informs HLR about current user location.
  • HLR sends acknowledgement (including the MS profile stored in HLR) to VLR
  • VLR informs MS of succesful registration (Welcome to Harayana!)
  • HLR sends de-registration msg to old VLR
  • Old VLR acknowledges de-registration.

b) Call Delivery Steps:

  • Query to get routable address passes from the PSTN to HLR to VLR.
  • The VLR returns the routable address from VLR to HLR to PSTN.
  •  Based on routable address, a trunk is set up.

The Decimal, Binary, Octal & Hexadecimal Number Systems

August 16th, 2011 No comments

A number systems is just a method used to "count" things. Usually, we count stuff using our fingers - from 1 to 9 and then add a tens place - 10 - 99. And so on. If we begin with a 0 instead of the 1 - We get what is called the DECIMAL number system. The base numbers of the system are the numbers which can alone be used to form other numbers in the system - {0,1,2,3,4,5,6,7,8,9} can form all the possible numbers in the decimal system. Since, there are 10 base numbers - the decimal system is sometimes, also called a base 10 number system.

Now consider this - computers don't use fingers to count. How do they count? - 0's & 1's. Hence comes the need for a new number system - {0, 1} that is a base 2 number system - called BINARY. Now, any number in the binary system will just use the two digits - 0 & 1. That is how number systems work.

In different applications, we need different ways of counting - which leads to new numbers systems.  Here are the four basic number systems and why they are used :

number_systems

Notice that the hexadecimal system used {A, B, C, D, E, F} for {10, 11, 12, 13, 14, 15, 16}. Do not get confused here. A is just 10 and nothing else. (And so on) Also, you can create any number system you want with any base. (Try creating a number system with base 6.)

Often, we need to know the binary equivalent of a decimal number(the computer needs that more than us, though) or say, the decimal equivalent of an octal number. Conversion between number systems is easier than you think. Study the following examples and you will be able to convert between any number systems you want -

Example #1

- Convert (44)10 to (?)2

Step 1 - We need to convert to binary which has a base 2. So start by diving the number in decimal by 2. Continue dividing and find the remainders for each division.

44/2 = 22 (R=0)
22/2 = 11 (R=0)
11/2 = 5 (R=1)
5/2 = 2 (R=1)
2/2 = 1 (R=0)
Now, we are left with 1 (R=1)

Step 2 - Starting from the last remainder, moving upwards - the remainders form the binary equivalent of the number.

R=1, R=0, R=1, R=1, R=0, R=0 => (101100)2

Example #2

- Convert (101100)2 to (?)10

Step 1 - Multiply the last digit by 20, the second last digit by 21 & so on. Remember step 2 in example one was written reverse. Hence, here - we start off with the reverse. (right to left)

0*20 = 0
0*21 = 0
1*22 = 4
1*23 = 8
0*24 = 0
1*25 = 32

Step 2 - Add all of the above to get your decimal equivalent.

0+0+4+8+0+32 => (44)10

We use the same above methods for converting between any two systems. More examples will give you an insight on this.

Example #3

- Convert (1690)10 to (?)16

Step 1 - We need to convert to hexadecimal which has a base 16. So start by diving the number in decimal by 16. Continue dividing and find the remainders for each division.

1690/16 = 105 (R=10=A; Remember the A in hexadecimal is nothing but 10)
105/16 = 96 (R=9)
96/16 = 6
Now, we're left with 6 (R=6)

Step 2 - Starting from the last remainder, moving upwards - the remainders form the hexadecimal equivalent of the number.

R=6, R=9, R=A => (69A)16

Example #4

- Convert (12AB)16 to (?)10

Step 1 - Multiply the last digit by 160, the second last digit by 161 & so on. (right to left)


When multiplying, just use A=10, B=11 ... & so on.

B = 11; 11*160 = 11
A = 10; 10*161 = 160
2*162 = 512
1*163 = 4096

Step 2 - Add all of the above to get your hexadecimal equivalent.

11+160+512+4096 => (4779)10

Now, you can use the same methods for any number systems. Just use repeated division while converting FROM decimal & repeated multiplication to convert TO decimal.

Try applying the same method for decimal to octal & back. Then make a program for it, (perhaps).

How to Make a Dot Matrix Business Card

August 8th, 2011 No comments

Another awesome project - A business card - with scrolling text on a dot matrix display. Full instructions on how to make one of these are available.

Dot Matrix Business Card in action :

The Fundamentals Of Communication Systems - Video Tutorials

August 7th, 2011 No comments

Here are videos explaining the very basics/fundamentals of communication systems. Hope they help :)

Part 1 :

Part 2:

Spinning LEDs - The Disco Ball

August 6th, 2011 No comments

Just came across this on YouTube. A really awesome LED Project. Must check it out, and don't forget this guy made it when he was 16.

 

Another Version :

Unfortunately, there are no schematics included. But that also gives us something to think about. So, what do you think?

DNS, IP, Subnets & All That Jazz

June 29th, 2011 No comments

Just like each place in the world has an address - Each machine on the internet has an address called the IP Address. For instance, your computer has an IP address, the server that hosts this website has an IP adress, and so on. And when we use "www.zarrata.com", we are actually referring to IP address "69.147.225.58" which is assigned to zarrata.com. You can find your own IP at http://whatismyipaddress.com/

Then, of course, we would need a database that has all the IP's corresponding to all the websites on the internet. It could then be used to translate the human-friendly address or domain names(zarrata.com) to the real(IP) address(64.197.225.58). This database is called the DNS (Domain Name System).

Now, an IP address is actually used in binary for communication by the computer. For instance, 216.27.61.137 translates to 11011000.00011011.00111101.10001001 - each number is represented by 8 positions in binary form - and are hence, called octets. The complete IP address is then a 32-bit number (made from 4 octets). Each of these 32 bits can be either 0 or 1 - thus allowing 2^(32) unique IP addresses which is about 4.3 billion possibilities.

[PS - The IP address considered here is the most prevalent version of the IP address - called IPv4. The other being IPv6]

ip_address_v4

Now, the first half of the IP address - the first 2 octets - 216.27 is the network part and the second half - the last 2 octects 61.137 form the machine or host part. ie-the first half is the neighborhood or street where you live and the second half is the exact house in the neighborhood. Hence, machines having the same first half of the IP belong to the same network. For instace, 129.144.50.56 & 129.144.23.122 belong to the same network.

Subnets & Subnetting

Networks having a large number of hosts are divided into subnetworks or subnets. A subnet number is assigned to each subnet. The second half or host part now has the host and the subnet number combined together - using the AND operation.

Consider a large network 192.168.10.0 that has the IP addresses ranging from 192.168.10.1 - 192.168.10.224

(225 is the maximum value of any octet - since, 256 is not an octect; 256 = 100000000. Here 224 is used since 192.168.10.255 is a BROADCAST ADDRESS and cannot be used).

Now, we wish to divide the network into two subnetworks:

The first network consisting of the machines 192.168.10.1 - 192.168.10.127

The second network consisting of the machines 192.168.10.128 - 192.168.10.225

It is done by using a subnet mask which is defined by :

1)The class of IP(see table below) - here, the mask to be used is 255.255.255.0

2)The address that divided the network - here, 192.168.10.128

Hence, the mask obtained from 1) & 2) is 255.255.255.128

Class Address Range Subnet Mask
Class A 1.xxx.xxx.xxx - 126.xxx.xxx.xxx 255.0.0.0
Class B 128.xxx.xxx.xxx - 191.xxx.xxx.xxx 255.255.0.0
Class C 192.xxx.xxx.xxx - 223.xxx.xxx.xxx 255.225.225.0
Class D 224.xxx.xxx.xxx - 239.xxx.xxx.xxx Reserved for multicast groups
Class E 240.xxx.xxx.xxx - 254.xxx.xxx.xxx Reserved for future use, research & development

[Note - 127.x.x.x addresses are reserved for loopback or localhost]

Pulse Code Modulation, Intersymbol interference & Eye Patterns

January 19th, 2011 No comments

Well, this post is more of an announcement - I started a YouTube channel and will try to make videos on most of the stuff i can related to Electronics & Communications, and perhaps, some other stuff too. So, to begin with, I decided to go for a set of videos on Communication Systems.

Check out the following videos on PCM, Intersymbol Interference & Eye Patterns. I'll be posting other videos on the blog wherever required. The best part is that they are light & hence, buffer really fast. Good Luck :)

The first video gives an introduction to how PCM works. The source produces an analog signal which has to be sampled, quantized & encoded to convert it into a pulse composed of only binary words. The binary words, represented by voltage pulses, are then transmitted. It gives a general block diagram of the PCM system.

isi

Intersymbol Interference

Once the signal is transmitted, noise affects the signal and the receiver must remove the additive channel noise. Since, the signal is a set of digital pulses, we only need to re-quantize it to remove noise. We then decode and reconstruct to get the required information(analog). Then, if bandwidth is decreased, we can observe effects of ISI which distorts the signal leading to a CRO pattern that appears to be a closed eye(called eye pattern)

The Basics Of VHDL Design

December 24th, 2010 No comments

What & Why?

To accomplish a particular electronics application, a specific combination of hardware and software is needed. For instance, the CPU is a processor based system which is essentially just a silicon chip with software that enables serial execution of instruction sets. For larger applications, our silicon chips are usually PLDs(programmable logic devices) like PAL, CPLD and FPGA.

The structure of an FPGA device - to be coded in VHDL

The structure of an FPGA device - to be coded in VHDL

Now, the software required for these chips(and many others - including ASIC devices) is coded in a HARDWARE DESCRIPTION LANGUAGE(HDL) like VHDL or Verilog. VHDL is a nested acronym that stands for Very High Speed Integrated circuits(VHSIC) Hardware Description Language.

VHDL allows us to view a design at various levels of abstraction - Simulation gives us the waveforms of the circuit inputs and outputs & Synthesis gives us the possible combinations of gates/transistors to achieve the required operation.

In VHDL, any circuit/system is viewed as an entity(or a set of entities). The internal working of an entity is called its architecture. For instance, to design a half adder using VHDL, the entity would be the half adder itself with its input and output ports & the architecture would tell VHDL what happens between the input & the output ports.

A Sample Code in VHDL

Here is a sample code to design a half adder using VHDL. It is just to see how entity & architecture together make up the whole circuit design.

entity half_adder is
port (A, B : in BIT; sum, carry : out BIT);
end half_adder;

architecture adder_architecture of half_adder is
begin
sum <= A xor B;
carry <= A and B;
end adder_architecture;

VHDL Libraries & Packages

Just like all other languages, VHDL has libraries that allow us to reuse certain frequently used pieces of code. The three basic libraries that go into almost all VHDL coding are -

library library_name;
use library_name.package_name.package_part;   --the syntax

library ieee;
use ieee.std_logic_1164.all;     
--use all parts of the std_logic_1164 package

library std;
use std.standard.all;    --added by default

library wprk;
use work.all;            --added by default

--these are comment lines, by the way.

All packages contain useful data types & keywords. A full specification/definition of the packages can be seen at http://www.csee.umbc.edu/portal/help/VHDL/packages/

Data Objects & Data Types in VHDL

In VHDL, data can be in the form of  a Constant, Variable or a  Signal - which are also the keywords for declaring the same. "File" in VHDL is a sequence of values and hence, is also considered a data object. Each of these objects are of some specified data type.

constant RISE : TIME;      --of type time
variable COUNT : INTEGER;  --of integer type
signal CLOCK : BIT;        --bit type

The following data types can be used in VHDL -

Scalar Types - enumeration, integer and floating point types including BOOLEAN, BIT, CHARACTER, INTEGER, NATURAL, REAL, etc.

Physical Literals - values representing physical quantities like CURRENT, VOLTAGE, etc. TIME is the only predefined literal(in the std package)

Composite types - contain a collection of values that may belong to different types like ARRAY and RECORD.

File Types - represents files in the host environment - help communicate with the host.

Operators in VHDL

Assignment Operators - used to assign a values to a data object. <= assigns a value to a signal & := assigns a value to a variable while => is used to assign values to individual/other vector elements.

signal x : bit;
x <= '1';

variable y : std_logic_vector (0 to 3);  
--y is a vector with 4 elements
y:="0000";

signal w : std_logic_vector (0 to 7);
w <= (0=>'1', others=>'0');   
--0th element is 1 and others are 0

Logical Operators - boolean logic ; all the basic logic gates. Data to be operated must be of type BIT, STD_LOGIC or STD_ULOGIC or their vector extentions.

Arithmetic Operators -  for arithmetic (not boolean) operations including +, -, *, / , **, MOD, REM, ABS

Relational Operators -  used for comparisons ( =, /=,  > , < , <= & >= )

Shift Operators -  shift logic left(sll), shift logic right(slr), shift left arithmetic(sla), shift right arithmetic(slr), rotate left(rol) & rotate right(ror) -

"1001010" sll 2 is "0101000"

--shift left by 2 and replace missing digits on right by zeros

"1001010" srl 4 is "0000100"

--shift right by 4 and replace missing digits on left by zeros

"1001010" sla 2 is "0101000"

--shift left by 2 and replace missing digits by rightmost bit
(here, 0)

"1001010" sra 4 is "1111100"

--shift right by 4 and replace missing digits by leftmost bit
(here, 1)

"1001010" rol 2 is "0101010"

--shift left by 2 while moving overlapped digits to the right
(here, 10)

"1001010" ror 1 is "0100101"

--shift right by 1 while moving overlapped digits to the left
(here, 0)

Note : rol -1 is the same as ror 1, sla -2 is the same as sra 2 and so on.

Concurrent & Sequential Design Models

Unlike the sequential statements in other programming languages, VHDL code is concurrent code - which is good enough to build combinational circuits . However, to build sequential circuits, we need sequential code. We can implement sequential code in VHDL using some specific statements.

To write concurrent code, use WHEN, GENERATE & BLOCK statements & to write sequential code, use the PROCESS, FUNCTION & PROCEDURE statements.

Example - A 4:1 MUX using Concurrent Code

library ieee;
use ieee.std_logic_1164.all;

entity mux is
port(a,b,c,d : in std_logic;
sel : in std_logic_vector(1 downto 0);
y : out std_logic);
end mux;

architecture mux_a of mux is
begin
y <= a when sel = "00"
else b when sel = "01"
else c when sel = "10"
else d;
end mux1;

Example - A Rising Edge-Triggered Delay FF using Sequential Code

library ieee;
use ieee.std_logic_1164.all;

entity dff is
port(clock, reset, d : in std_logic; y : out std_logic);
end dff;

architecture dff_a of dff is
begin

process(reset, clock)
--the sensitivity list contains objects that can
cause the process to execute.
begin

if(reset <= '1') then q <= '0'
elseif (clock'EVENT and clock = '1') then q <= d;
--if an event occurs on clock and the event is a rising edge
end if;

end process;

end dff_a;