+ All Categories
Home > Documents > Programming Languages - Webs

Programming Languages - Webs

Date post: 12-Feb-2022
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
36
Page 1 of 36 Form 5 Theory Notes Programming Languages What is a program? A program is a set of instructions, followed by a computer to perform a specific job. What is a programming language? A programming language contains a specific set of commands which have clear functions to perform a specific task IMPORTANT: A command used in a programming language must have no ambiguous meaning: Eg: The word DRAW can mean paint and can also mean extract. Such word cannot be used as a command in a programming language Eg: The word WRITE has only one clear meaning, that to write something, therefore such word can be used as a command in a programming language. Types of instructions: Input/Output Arithmetic Data Comparison of Variables Conditions All commands have a particular operation purpose and therefore that is why all instructions are called OPERATION CODE .
Transcript

Page 1 of 36

Form 5 Theory Notes

Programming Languages

What is a program?

A program is a set of instructions, followed by a computer to perform a

specific job.

What is a programming language?

A programming language contains a specific set of commands which have

clear functions to perform a specific task

IMPORTANT:

A command used in a programming language must have no ambiguous

meaning:

Eg: The word DRAW can mean paint and can also mean extract. Such word

cannot be used as a command in a programming language

Eg: The word WRITE has only one clear meaning, that to write something,

therefore such word can be used as a command in a programming language.

Types of instructions:

Input/Output

Arithmetic

Data

Comparison of Variables

Conditions

All commands have a particular operation purpose and therefore that is why

all instructions are called OPERATION CODE.

Page 2 of 36

Form 5 Theory Notes

LOW LEVEL LANGUAGES – More Close to Machinery

Advantages:

1. Languages more compatible with machines

2. Designed to translate machine code faster

3. Use simple instructions called mnemonics

Disadvantages:

1. Harder to understand

2. Few people know how to use such languages

3. Ambiguous to learn such language

EXAMPLES OF LOW LEVEL LANGUAGES:

Assembler

Machine Code (1110000111000)

PROGRAMMING

LANGUAGES

LOW LEVEL

LANGUAGES

HIGH LEVEL

LANGUAGES

Page 3 of 36

Form 5 Theory Notes

HIGH LEVEL LANGUAGES – More Close to how humans

understand

Advantages:

1. Commands similar to natural languages

2. Many different languages to choose from

3. Many programmers understand and use such languages

4. Easy to compare one language with other

Disadvantages:

1. Machine needs more intensive translation

2. Slower execution

3. Programs larger in size and use more memory

EXAMPLES OF HIGH LEVEL LANGUAGES

Pascal

Java

Cobol

Use of Programming Languages in real life

Use of Low level languages – Critical Parts of Code in a Program

Use of High level languages – All our computer software such as operating

systems, games etc

Programming Languages Generations

3 generation languages (3GL): Languages which require programmer to

specify what must be done and how it has to be done

EG: Programs written in Java, Pascal, Visual basic, C# like an Antivirus,

Firewall, Computer Upgrades

4generation languages (4GL): Languages which can be used by less

experienced users as most of them contain an easy user interface how to use

the language. They are very similar in use to every day application packages.

EG: SQL, database packages, payroll systems, POS systems

Page 4 of 36

Form 5 Theory Notes

Assemblers, Interpreters and Compilers

Assemblers, Interpreters and Compilers are the medians between user

interface and computer interface. All 3 types of software change Source

Code to Machine Code

IMPORTANT:

All type of instructions finally must be changed to machine code,

combinations of 1s and zeros so that the computer understands.

Assembler (Low level languages)

Used to translate assembly code (mnemonics) to machine code(1110000)

Compiler (High level languages)

Used to translate source code (Pascal Instructions) to machine code. All

code is translated at the same time.

Interpreter (High level languages)

Also used to translate source code to machine code with the difference that

translates one instruction after the other.

Source Code

( My Pascal Program)

Object Code

(Black Screen output .exe)

TRANSLATION

Page 5 of 36

Form 5 Theory Notes

Interpreters vs Compilers

Compilers: o Complex software to create ( It is not easy to create a compiler

yourself)

o Faster to execute

o Most High level languages use compilers

o Occupies memory for less time – only while compiling

o Errors listed at the end of program

Interpreters: o Easier to create (Create an interpreter yourself)

o More helpful for user to do debugging

o Occupies memory for longer time – memory used for every

interpretation

o Slower Execution

o Easier to find errors – Program stops until error is solved

COMPILER

Source Code

Object Code Object Code

INTERPRETER

Source Code

Page 6 of 36

Form 5 Theory Notes

ASCII code

What is ASCII code?

ASCII code is a set of symbols each made up of a combination of 8 bits.

There are 256 different symbols (28

) these include all the letters of the

alphabet in small and capital, the numbers from 0-9 and various graphical

symbols.

Every time we click on our keyboard a matching ASCII code is registered in

the memory. The ASCII code is then translated into binary code.

Keyboard Button ASCII code Binary for CPU

A 65 01000001

J 74 01001011

All computations and programming languages use such coding system to

perform translation between a natural language we understand and the

electronic pulses the computer understands.

Other Coding systems are:

o Extended ASCII

o UNICODE

Page 7 of 36

Form 5 Theory Notes

Operating Systems and Networks

Operating System (OS)

An OS is a system software which is essential to control ANY computer and

controls ALL other programs used in the system.

Main functions of an Operating System:

1. Accepts user commands, performs requested task and reports back to

user. (Normal use taken for granted)

2. Loads programs and instructs CPU to run ( Computer Running)

3. Allocates required resources (memory, peripherals) to run programs

4. Controls and monitors all data transfers

5. Reports to user malfunctioning of system

USER/APPLICATION

OS

PC

Page 8 of 36

Form 5 Theory Notes

Important programs in an OS – UTILITIES

System utilities are small programs which form part of an operating system

and perform important jobs such as:

Format disks

Back up

System Restore

Disk Defragmenter

Popular Operating System Utility Programs

Resident loader – loads/copies programs from backing storage onto central

memory for eventual use.

Command Processor – Program which controls the command execution.

(Every instruction sent to CPU to be executed is analyzed and controlled to

perform appropriate function by the program)

File Manager – Responsible for the organization of data files in our system.

Keeps track of our files stored. Matches symbolic address eg. Mydoc.txt

with physical address in memory

Peripheral Drivers – Supplied software installed for communication with

peripheral devices.

How an operating system is made up

An operating system is divided into two main sections:

The internal aspect where: file management, memory management and

loading of programs are involved.

The internal part is called the SHELL or KERNEL

The external view where the user manages the operating system,

nowadays it is made up of graphical icons, menus and windows.

Page 9 of 36

Form 5 Theory Notes

The modern external view is called GUI – Graphical User Interface

In the past there was a simple black screen where the user typed the

commands required.

The old external view is called CLI – Command Line Interpreter

Different types of Operating Systems

a. Batch Processing - A type of Operating system which performs

only 1 job at a time and can perform repetitive tasks

automatically. Jobs are queued one after the other (batches)

Advantage:

Operating system programming is very simple and easy to control.

Disadvantages:

Very slow process and limited output efficiency

Minimal use of CPU and memory, these resource have to

wait until the input and output process is finished

Page 10 of 36

Form 5 Theory Notes

Batch processing nowadays are still used for repetitive tasks which

require no human intervention:

Printing of cheques in government departments

Companies transactions updates: Supermarket stock update

b. Multiprogramming – A type of parallel form of processing in

which several programs run at the same time using 1 processor.

Since there is one processor each program must wait for its turn

of CPU time.

It works by giving a slice of CPU time to all the programs in

the queue, therefore many programs can start and finish at the

same time. Such system is called ROUND ROBIN SYSTEM

Advantage:

Better CPU and memory management

More tasks are accomplished in a certain amount of time

Disadvantage:

Operating System more complex

(The term multi programming refers to how the system works

internally when it has to manage many programs at the same time)

CPU

JOB 1

JOB 2

JOB 3

Page 11 of 36

Form 5 Theory Notes

Terms related to Multiprogramming

SPOOLING

A similar system is used when printing. The term Spooling is used

to refer to a system where each job waits in a queue for its turn of

buffer time instead of CPU time to be printed.

MULTI TASKING

Multi tasking is a term related to multi programming, it refers to the

external part where an end user is performing many tasks at the

same time.

Eg: Listen to an mp3 file and using the word processor at the same

time.

c. Time Sharing (multi-user) - A type of operating system which was

commonly used in the 1970s. A single computer was shared

between many users. Each user had a monitor and a keyboard but

shared the CPU and the memory with other users. Each user

waited for his turn to complete a transaction.

It used the same principle of multiprogramming but instead of

sharing CPU and memory between programs, it shared them

between different computer users.

It reduced the hardware costs for the companies

The disadvantages were: slow processing and updates where

not done immediately.

(A computer which has no memory and cpu is called Dumb terminal)

Page 12 of 36

Form 5 Theory Notes

d. Real time Operating Systems – A type of Operating system which

performs a process within a certain amount of time. An RTOS

performs its tasks with precise timing and high degree of

reliability.

Examples:

Airbag Car System

Airplane control Buttons

ATMs

e. Online Operating Systems – A system which is continuously

connected through the internet. Different users from different

parts of the world can send data and the system is immediately

updating its data.

Example:

Internet Application forms and subscriptions

f. Networked Systems – An operating system which its main idea to

connect many computers to one main control point (Server).

It shares data and peripherals (printers, scanners)

The main responsibility of such system is to control data traffic and

the access resources by different users.

Page 13 of 36

Form 5 Theory Notes

Names of Operating Systems used in General Computers and

Dedicated Computers

MS/DOS: Command Prompt Operating System (Available also as an

extra function in our pc – Start Accessories Command Prompt)

UNIX: A very popular operating system which is used in large systems

and networks. Mostly known as a server operating system

MS Windows: XP, Vista, Windows 7 – Most commons Operating

System used nowadays

MAC: Operating system designed for Macintosh machinery

Android: Operating system mainly designed for smart phones and

touchpads.

Dedicated and General computers

All types of computers require an operating system to start performing any

minimal function. Operating systems are used in personal computers, pda,

mobiles, mp3, mp4. Each requires an adaptive operating system according to

its requirements.

The two common types of computers which require an Operating System

are:

Dedicated computers

General computers

A dedicated computer is a hardware which is dedicated to a single

application, eg: Washing machine, MP3 player

A general computer is a hardware which is dedicated to general tasks

such as office applications, games, internet access.

Page 14 of 36

Form 5 Theory Notes

Networks

What is a network?

Networks are made up of a number of personal computers, connected

together to be able to share data and expensive peripheral resources.

Advantages of a network:

o Sharing of Data

o Sharing of Hardware

o Sharing of Software

Disadvantages of a network

Requires more Security software installation and maintenance

System is more complex to implement

Security methods used in networks to transfer data

Encryption – The encoding of data before being transferred from

one computer to another.

Encryption is the process of changing data into a meaningless code.

Only authorized users can receive the data into its original form.

Decryption – The decoding of data to its original format when it is

received by the authorized user

Decryption is the process of converted encrypted data back to its

original form, this process is done immediately after the data is

transferred to the specific user/s.

Page 15 of 36

Form 5 Theory Notes

Types of networks

LAN: Local Area Network

WLAN: Wireless Local Area Network

WAN: Wide Area Network

MAN: Metropolitan Area Network

PAN/Piconet: Personal Area Network

Wifi: Wireless Network / Infrared / Bluetooth

The Local Area Network (LAN/WLAN)

Several computers linked together within a limited area (building). Each

computer forming part of the network is called a node. If the network is

linked using cables(wires) it is a LAN, if the network is linked using

wireless mediums it is called a WLAN.

Different LAN topologies (Configurations)

What is a topology?

Topology is a way of configuring the various nodes within a network to

connect with each other and control data traffic.

Star Network Topology

Ring Network Topology

Line Network Topology

Page 16 of 36

Form 5 Theory Notes

All connection settings create a star shape in wiring

Connection setting and wiring form a ring shape network

THE RING NETWORK TOPOLOGY DIAGRAM

THE STAR NETWORK TOPOLOGY DIAGRAM

Page 17 of 36

Form 5 Theory Notes

A main wire supports all nodes connected to it

The Wide Area Network (WAN)

The most popular WAN is the Internet

A WAN spans linkage through large boundaries either nationally and even

internationally.

Different types of connection topologies form part of a WAN:

o Modems using telephone lines

o Satellite connections are commonly used

o Wireless connections

The Metropolitan Area Network (MAN)

A type of network which is larger than a LAN but smaller than a WAN.

Such network spans over a campus or a city. Often made up of several

LANS connected together through a main backbone.

A MAN offers high speed network coverage and can be used contemporary

with LAN and WAN.

Eg: My Company can be a LAN itself, connected to the internet by a WAN

and forms part of my city network (MAN).

THE LINE/BUS TOPOLOGY NETWORK DIAGRAM

Page 18 of 36

Form 5 Theory Notes

The Personal Area Network (PAN) A small network usually made up of handheld devices such as PDAs and

mobile phones.

Wireless PANS

Infrared: Makes use of light waves. Line of sight transmission standard

Bluetooth: Makes use of radio frequency band.

ISM band frequency – Industrial, Scientific and Medical Services

Interference – used to control transmission

Network Mediums (Hardware) required to create a network

Cables – Wiring used to link computers together and create internet link.

Types of wires used are:

Ethernet cable – Internet Connection

Telephone cable – Internet Connection

Fiber Optic cable – Internal network connection

Coaxial cable – network connection

Modem / Router / Switch – Devices which change analogue to digital data

and vice versa when using the internet.

Modem – small systems with less than 3 computers

Router – a type of modem but more powerful used for longer

distances and larger amount of computers connected in a system

Switch – a very powerful type of modem used in large areas to cater

for many computers located in different areas.

Page 19 of 36

Form 5 Theory Notes

Distribute and Centralized Data Setups

Data in large network systems is stored in a File Server, a computer which

its only purpose is to store and manage the data within a network.

There are two main types of setups which can be used in a network, these

are:

Centralized Data System

A file server is responsible for entire data system. All branch computers

communicate with it to get the data required.

Advantages:

Faster access

Easy to control and safeguard – if there is a fault it must be in the only server

used.

Disadvantage:

If the file server is fault the entire system stops

Distributed Data System

Different sections in a network have their local data storage. Each server

communicates with other server through the main file server to get the

required data.

Advantages:

Failure in a section does not disturb other branches

Network traffic is reduced

Disadvantage:

Centralized control is lost – if there is a fault all the servers must be checked

to trace the fault.

Page 20 of 36

Form 5 Theory Notes

The Internet

What is internet?

Internet is a global network of many computer networks. Various methods

of connections like ADSL, cable and satellite connections are used to access

data from around the world.

Internet History

1969: First Internet Ideas in USA by DARPANET

1972: 37 computers connected together. Network known as ARPANET

1983: Too many users connected. New military network created called

MILNET

1984: Great step forward, 5 supercomputers where used as they were very

expensive. Network called NSFNET

1987: NSFNET was upgraded with faster telephone lines

Early 1990s: Internet was created using a dial up system

Late 1990s: ADSL became most popular internet connection

2000- today: Many new technologies such as Bluetooth, wireless networks

are available

Page 21 of 36

Form 5 Theory Notes

Different use of Internet

Email

Browsing

File Transfer – Downloads

Social networking sites

E-Commerce – Ebay

Streaming

To have access to any of these functions one must have an internet

connection, an ISP- Internet Service Provider (GO, Vodafone, Melita)

provides a connection link to your home.

EMAIL

Email stands for electronic mail, every email is transferred from sender to

recipient using a set of global protocols (laws). These include rules about:

o Email address format [email protected]

o Data size to be sent

o Encryption of data

o Decryption of data

Every email moves by using these protocols (laws)

o SMTP

o TCP/IP

o POP or IMAP

BROWSING

It requires the use of browser software such as Internet Explorer, Mozilla

Firefox, Google Chrome.

Make use of hypertext which is all the text, pictures and animation found in

a website.

Each website to be browsed must have an URL (Website Address)

Page 22 of 36

Form 5 Theory Notes

Technical definition of a website

Websites are sets of files uploaded on the internet to be accessed globally by

different users who have access to the internet.

When you are browsing, it means that you are using different files uploaded

by various users from different countries.

FILE TRANSFER

The process of downloading and uploading data in different formats over the

internet. Data can be in form of : audio, video, pictures and text.

Each file transfer makes use of the FTP protocols which allow users to send

and receive data using the internet.

Legal downloading of software:

Freeware: software available for free to download and use with author

permission

Shareware: software available for free for a trial period, then you either buy

it or remove it from your system

Upgrades: often given for free when you buy original software, to keep your

software updated with the latest changes

Patches: small programs used to make up for a bug which the original

software might contain.

Page 23 of 36

Form 5 Theory Notes

SOCIALIZING

A recent service used over the internet, where different users from around

the world create a profile with personal information and share with the other

users in the network.

Popular social networking sites:

o Facebook

o Tweeter

o Skype

o Msn

E-COMMERCE

E-commerce refers to the process of making business using online service.

Users can sell or buy items from other users or from companies. It involves

online payment using either credit cards (VISA) where the money is directly

deducted from your personal bank account or via paypal.

Online shops – Companies or businesses which sell their products through

the internet. They either have a business website or use larger trading

websites such as E-bay.

Paypal - In Europe, PayPal is registered as a bank in Luxembourg under the

legal name PayPal (Europe), it is a secure method of payment, where the

buyer has 45 days to claim for refund if the item purchased is not delivered

or is damaged.

STREAMING

An online service where users can view programs and videos over the

internet. Many popular tv stations are also transmitting their programs

through streaming. Compared to television services it is slower and

sometimes it has interference, this is due to the large amount of files being

transferred at the same time, all transfers must pass a set of FTP protocols.

Page 24 of 36

Form 5 Theory Notes

Multimedia

What is Multimedia?

The term multimedia is used to define the use of several media options, such

as movies, slides, music, and lighting in combination normally for the

purpose of education or entertainment.

Multimedia presentations may be viewed on stage, projected, transmitted,

played on a media player.

Multimedia games and simulations require physical environment with

special effects, user online in a network.

Usage

Multimedia applications are used in various areas for a variety of purposes:

Advertisements

Art

Education

Entertainment

Engineering

Industry

Medicine

Mathematics

Business

Scientific Research

Virtual Reality

Page 25 of 36

Form 5 Theory Notes

Multimedia Contents

Multimedia contains a combination of contents forms:

Text

Audio

Still Images

Animation

Video

Interactivity (eg: Mouse pointer)

Categories of Multimedia

Linear: Content progress without any navigation control from viewer.

Eg: Cinema presentation

Non linear: Offers user interactivity with control progress

Eg: Computer Game

Virtual Reality

What is virtual reality?

Virtual reality uses multimedia applications which create an environment or

situations which do not physically exist. It is mostly used in scientific

research and entertainment parks. Nowadays virtual reality can also be

created on a smaller scale at home when we use various gaming consoles.

These make use of sensors which detect our movements and output them on

screen.

Applications and delivery platforms of multimedia are virtually limitless

Page 26 of 36

Form 5 Theory Notes

Assembly Language

Assembly language is a low level language which is the closest to machine

code

Machine code refers to combinations of zeros and ones. Each combination

performs a particular function.

Mnemonics

Mnemonics are short instructions used to perform a function. Assembly

language is made up of mnemonics instead of instructions.

Mnemonics perform just one instruction at a time

When using assembly language you have to know exactly which registers or

memory locations you are using.

The Registers are either 8 bit registers or 16 bits registers meaning they can

store 8 bits or 16 bits.

Registers: A register can be 4 bit /8bit/ 16bit /32bit and modern systems even 64bit

IR Instruction Register

PC Program Counter

Acc/ A Accumulator (Stores result of the output performed by

mnemonics)

OUT Output Unit

MAR Memory Address Register (Stores Address of memory location of

mnemonic currently being executed)

MDR Memory Data Register (Stores data of an instruction currently

being executed)

100 -102 particular locations in memory/memory location can be given a

variable name instead of actual address in the memory chip.

Page 27 of 36

Form 5 Theory Notes

Mnemonics are made up of OPCODE and OPERAND

ADD A, 3;

ADD – opcode

3 – operand

Direct Addressing and Indirect Addressing

Direct Addressing is when you call a memory location by its original

address (number) MOV 102, 2;

Indirect Addressing is when you call a memory location using variable

names

MOV XYZ, 3;

Registers can be called using their actual name given by manufacturer or

else refer to a particular register as Register A..Register B.....etc

Sometimes data to be inserted (mostly numbers) have the letter h written

next to them this means that this number is of type hexadecimal.

MOV XYZ, 9h;

ASSEMBLY CODE SNIPPETS

The very first step when using assembly language is to know how to insert a

value.

By default the location is set as ACCUMULATOR, however you can set

your values in any register or location which can be accessed.

Inserting the value 5 in the accumulator:

IN 5;

MOV 5;

Inserting the value 5 in memory location 200:

IN 200, 5;

MOV 200;

Inserting the value 5 in memory location 200 and output its content:

Page 28 of 36

Form 5 Theory Notes

IN 200, 5;

MOV 200;

OUT 200;

You can also label a memory location with any name you like, and insert

numbers or strings:

MOV myvar, 2000;

Put the value 2000 in a memory location labeled myvar

Therefore the variable myvar is representing an actual memory location

within your memory chip

Simple Program using Direct Addressing

IN 600, 250;

MOV 600;

MUL 600, 2;

MOV 600;

OUT 600;

In this program the content of memory location 600 which is 250 is being

multiplied by 2 and the answer is printed on screen

Using Direct Addressing with Jump functions

A jump function is similar to a loop in a high level language.

IN 300, 2000; (Put value 2000 in memory location 300)

Loop1: DIV 300, 2; ( Divide the value in memory location 300 by 2)

CMP 300 < 100 (Compare value obtained if it is less than 100)

JLESS Stop ( if value in memory location is less than 100 then stop

program)

JMP Loop1; ( repeat again steps found in loop1)

Stop End

Using JMZ – Perform a jump if answer is not zero

Page 29 of 36

Form 5 Theory Notes

IN 100, 25;

Loop 2 : MOV 100;

SUB 100, 1;

OUT 100;

JNZ Loop 2;

This program inserts the value of 25 in memory location 100, prepares

location 100 for a function and then subtracts 1 from the value stored in

location 100. Prints the value and then checks if value is zero or not. If it is

not zero it repeats loop 2 from the start, if the answer is zero it exits the

program.

Common Jumps commands

JZ Jump if output is zero

JNZ Jump if output is not zero

JE Jump if equal

JNE Jump if not equal

JG Jump if greater

JGE Jump if greater than or equal

JL Jump if less

JLE Jump if less than or equal

Try to understand how this program works:

In 20, 50;

Mov 20;

Add 20, 100;

Mov 20;

Out 20;

{Output Input the value 50 in location 20, prepare location 20 for another function,

add 100 to he value already stored .Output the result found in location 20, result in

location 20 is 1

Page 30 of 36

Form 5 Theory Notes

Simple Programs using Indirect Addressing

IN my_loc, 2000;

OUT my_loc;

Input the value 2000 in a memory location which you labeled my_loc, show

its content.

IN my_memory_location, 60;

ADD my_memory_location ,30;

OUT my_memory_location;

Input value 60 in a memory location which you labeled

my_memory_location, add the value of 30 to its content, show its content. In

this case it outputs 90.

IN AX, 60;

MOV AX;

SUB AX, 20;

OUT AX;

Use register called AX and input the value 60 in it, prepare it for a function,

in this case the subtraction, Output the result. In this example the result is 40.

Using Indirect Addressing with Jump function Same program using Indirect Addressing

In A 2000; (Put value 2000 in memory location called A)

Loop2: Div A 2; ( Divide the value in memory location Aby 2)

Cmp A< 100 ( Compare value obtained if it is smaller than 100)

JLE Stop ( if value in memory location is less than 100 then

stop program)

JG Loop2; ( repeat again steps found in loop2)

Stop: End

Page 31 of 36

Form 5 Theory Notes

Advanced Logic Gates

The main 3 logic gates used are:

NOT

AND

OR

However in many we use gadgets which are made up of 2 in 1 logic gates

These are:

NAND – AND gate combined with NOT gate The Negated AND, NO AND or NAND gate is the opposite of the digital AND gate, and

behaves in a manner that corresponds to the opposite of AND gate, as shown in the truth

table on the left.

TRUTH TABLE CIRCUIT SYMBOL

BOOLEAN EXPRESSION

Comparison of output with AND and NAND gate output

A B A.B A NAND B

0 0 0 1

0 1 0 1

1 0 0 1

1 1 1 0

Page 32 of 36

Form 5 Theory Notes

NOR – OR gate combined with NOT gate

The Negated OR, NO OR or NOR gate is the opposite of the digital OR gate, and

behaves in a manner that corresponds to the opposite of OR gate, as shown in the truth

table on the left.

TRUTH TABLE CIRCUIT SYMBOL

A NOR B (also written as A ↓ B)

BOOLEAN EXPRESSION

Comparison of output with AND and NAND gate output

A B A+B A NOR B

0 0 0 1

0 1 1 0

1 0 1 0

1 1 1 0

All circuits made up from AND/OR/NOT can be also created using NANDs or NORs

Page 33 of 36

Form 5 Theory Notes

Advanced Binary Functions

Binary refers to the 0s and 1s used to manage and transport data between the memory and

the CPU.

The CPU is divided into various sections which have different tasks within the system:

The main sections which control the memory functions are:

MAR – Memory Address Register

MDR – Memory Data Register

Registers – Various registers which are used for binary floating, calculations and

logic operations.

MAR – It holds the address location where the actual data is stored in the memory. It is a

pointer to the location which indicates the precise part of memory from the data is being

accessed.

MDR – It holds the data on which a computer function is being executed. By data we

mean streams of binary numbers which allow the CPU to understand the information we

input in the computer.

Registers – Small memory locations used to perform many logic and mathematical

functions required by the CPU to perform a task. These registers are also known as shift

registers as their main function is to modify streams of bits by shifting left or right

streams of bits.

Page 34 of 36

Form 5 Theory Notes

Shifting data in Registers

Example 1: Shifting data in Register A by 1 place to left

Register A – Original Data (Decimal Value of this register is 12

0 0 0 0 1 1 0 0

After 1 shift to the left the value of the original data will change as follows

0 0 0 1 1 0 0 0

The 0 on the last position in the left is dropped from the register, and the empty space is

ALWAYS filled with zero.

The value of the register is now 24

Example 2: Shifting data in register B by 1 position left

Original Value of Register B = 73

0 1 0 0 1 0 0 1

1 0 0 1 0 0 1 0

After 1 shift to the left the value of Register B =146

As one can notice from the output of these two examples, with every shift on left the

value of the register is doubles (as if multiplied by 2)

Page 35 of 36

Form 5 Theory Notes

Example 3: Shifting data in register C by 1 position left (but last bit is a 1)

Value in Register C = 132

1 0 0 0 0 1 0 0

1 0 0 0 0 1 0 0 0

We cannot drop the last digit if it is a 1 therefore we store the stream of bits into a 9 bit

register instead of 8 bit register.

Value in Register C = 264

Example 4: Shifting data in Register A by 1 place to right

Register A – Original Data (Decimal Value of this register is 12

0 0 0 0 1 1 0 0

After 1 shift to the right the value of the original data will change as follows:

0 0 0 0 0 1 1 0

The 0 on the last position in the right is dropped from the register, and the empty space is

ALWAYS filled with zero.

The value of the register is now 6

Page 36 of 36

Form 5 Theory Notes

Example 5: Shifting data in Register A by 1 place to right

Register A – Original Data (Decimal Value of this register is 8

0 0 0 0 1 0 0 0

0 0 0 0 0 1 0 0

After 1 shift to the right the value of the original data will change as follows:

The 0 on the last position in the right is dropped from the register, and the empty space is

ALWAYS filled with zero.

The value of the register is now 4

The shift right therefore is like dividing the binary value by 2, if the last value to be

dropped from the register is a zero then it divides the value exactly by half.

Multiply by 2 Shift left 1 place

Multiply by 4 Shift left 2 places

Multiply by 8 Shift left 3 places

Division by 2 Shift right 1 place

Division by 4 Shift right 2 places

Division by 8 Shift right 3 places


Recommended