0% found this document useful (0 votes)
146 views

COA Lab Manual

Uploaded by

Keep learning
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
146 views

COA Lab Manual

Uploaded by

Keep learning
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

LABORATORY MANUAL

COMPUTER ORGANIZATION AND ARCHITECTURE

SUBJECT CODE: 3140707


INFORMATION AND COMMUNICATION TECHNOLOGY
DEPARTMENT

B.E. 4TH SEMESTER

Name:

Enrollment number:

Batch:

Year:

Adani Institute of Infrastructure Engineering (AIIE)


Shantigram Township
Nr Vaishnodevi Circle, SG Highway
Ahmedabad 382 421
Gujarat, India
INDEX
Sr. Title Date Sign.
No.
PRACTICAL: 1
Aim : Write the working of 8085 simulator GNUsim8085 and basic architecture of
8085 along with small introduction.

➢ Working Of 8085 Simulator GNUSim8085:

GNUSim8085 is a graphical simulator, assembler and debugger for the Intel 8085 microprocessor
in Linux and Windows. It contains a simple editor component with syntax highlighting. Also it has
a keypad to input assembly language instructions with appropriate arguments.

(The image above shows default appearance of the GNUSim8085.)


Below are the characteristics highlights of the simulator GNUSim8085

• A keypad to input assembly language instructions with appropriate arguments.

• Easy view of register contents.

The register contents by default are set to zero

• Easy view of flag contents.

The flag contents by default are set to zero

• Hexadecimal <–> Decimal converter.

• View of stack, memory and I/O contents.

• Support for breakpoints for program debugging.

• Stepwise program execution.

• One click conversion of assembly program to op code listing.

• Printing support.

• UI translated in various languages


➢ Basic Architecture Of 8085 :

The 8085 microprocessor was made by Intel in mid 1970s. It was binary compatible with 8080
microprocessor but required less supporting hardware thus leading to less expensive microprocessor
systems.

It is a general purpose microprocessor capable of addressing 64k of memory. The device has 40
pins, require a +5V power supply and can operate with 3 MHz single phase clock.

It has also a separate address space for up to 256 I/O ports. The instruction set is backward
compatible with its predecessor 8080 even though they are not pin-compatible.

The 8085 has a 16 bit address bus which enables it to address 64 KB of memory, a data bus 8 bit
wide and control buses that carry essential signals for various operations. It also has a built in
register array which are usually labelled A(Accumulator), B, C, D, E, H, and L. Further special-
purpose registers are the 16-bit Program Counter (PC), Stack Pointer (SP), and 8-bit flag register F.
The microprocessor has three maskable interrupts (RST 7.5, RST 6.5 and RST 5.5), one Non-
Maskable interrupt (TRAP), and one externally serviced interrupt (INTR). The RST n.5 interrupts
refer to actual pins on the processor a feature which permitted simple systems to avoid the cost of a
separate interrupt controller chip.

Control Unit

Generates signals within microprocessor to carry out the instruction, which has been decoded. In
reality causes certain connections between blocks of the processor be opened or closed, so that data
goes where it is required, and so that ALU operations occur.

Arithmetic Logic Unit

The ALU performs the actual numerical and logic operation such as ‘add’, ‘subtract’, ‘AND’, ‘OR’,
etc. Uses data from memory and from Accumulator to perform arithmetic and always stores the
result of operation in the Accumulator.

Registers

The 8085 microprocessor includes six registers, one accumulator, and one flag register, as shown in
Fig 1. In addition, it has two 16-bit registers: the stack pointer and the program counter. The 8085
has six general-purpose registers to store 8-bit data; these are identified as B, C, D, E, H, and L as
shown in Fig 1. They can be combined as register pairs - BC, DE, and HL - to perform some 16-bit
operations. The programmer can use these registers to store or copy data into the registers by using
data copy instructions.

Accumulator

The accumulator is an 8-bit register that is a part of arithmetic/logic unit (ALU). This register is
used to store 8-bit data and to perform arithmetic and logical operations. The result of an operation
is stored in the accumulator. The accumulator is also identified as register A.

Flag Registers

The ALU includes five flip-flops, which are set or reset after an operation according to data
conditions of the result in the accumulator and other registers. They are called Zero(Z), Carry (CY),
Sign (S), Parity (P), and Auxiliary Carry (AC) flags. The most commonly used flags are Zero,
Carry, and Sign. The microprocessor uses these flags to test data conditions.
Program Counter (PC)

This 16-bit register deals with sequencing the execution of instructions. This register is a memory
pointer. Memory locations have 16-bit addresses, and that is why this is a 16-bit register. The
microprocessor uses this register to sequence the execution of the instructions. The function of the
program counter is to point to the memory address from which the next byte is to be fetched. When
a byte (machine code) is being fetched, the program counter is incremented by one to point to the
next memory location.

Stack Pointer (SP)

The stack pointer is also a 16-bit register used as a memory pointer. It points to a memory location
in R/W memory, called the stack. The beginning of the stack is defined by loading 16-bit address in
the stack pointer.

Instruction Register / Decoder

This is a temporary store for the current instruction of a program. Latest instruction is sent to here
from memory prior to execution. Decoder then takes instruction and ‘decodes’ or interprets the
instruction. Decoded instruction is then passed to next stage.

Memory Address Register (MAR)

Holds addresses received from PC for eg: of next program instruction. MAR feeds the address bus
with address of the location of the program under execution.

Control Generator

Generates signals within microprocessor to carry out the instruction which has been decoded. In
reality it causes certain connections between blocks of the processor to be opened or closed, so that
data goes where it is required, and so that ALU operations occur.

Register Selector

This block controls the use of the register stack. Just a logic circuit which switches between
different registers in the set will receive instructions from Control Unit.

8085 System Bus

The microprocessor performs four operations primarily.


• Memory Read
• Memory Write
• I/O Read
• I/O Write

All these operations are part of the communication processes between microprocessor and peripheral
devices. The 8085 performs these operations using three sets of communication lines called buses -
the address bus, the data bus and the control bus.

Address Bus

The address bus is a group of 16 lines. The address bus is unidirectional: bits flow only in one
direction – from the 8085 to the peripheral devices. The microprocessor uses the address bus to
perform the first function: identifying a peripheral or memory location. Each peripheral or memory
location is identified by a 16 bit address. The 8085 with its 16 lines is capable of addressing 64 K
memory locations.

Data Bus

The data bus is a group of eight lines used for dataflow. They are bidirectional: data flows in both
direction between the 8085 and memory and peripheral devices. The 8 lines enable the
microprocessor to manipulate 8-bit data ranging from 00 to FF.

Control Bus

The control bus consists of various single lines that carry synchronization signals. These are not
groups of lines like address of data bus but individual lines that provide a pulse to indicate an
operation. The 8085 generates specific control signal for each operation it performs. These signals
are used to identify a device type which the processor intends to communicate
PRACTICAL: 2
Aim : Write an assembly language programming for addition of two 8bit unsigned nos.
a)With carry provision b) Without carry provision

Input : (a) Output: (a)

7000 LDA 7100H


7003 MOV B,A
7004 LDA 7101H
7007 ADD B
7008 STA 7102H
700B HLT

Input : (b) Output: (b)

7000 MVI C,00H


7002 LDA 7101H
7005 MOV B,A
7006 LDA 7102H
7009 ADD B
700A JNC ahead
700D INR C
700E ahead STA 7103H
7011MOV A,C
7012 STA 7104H
7015 HLT
Oral Based Questions.

Q1. How many different instructions Microprocessor 8085 have? What is an instruction set?
Ans. 8085 microprocessor has a total of 74 different instructions for performing different operations or tasks.
The entirely different instructions that a particular microprocessor can handle is called its instruction set.

Q2. What an instruction consists of?


Ans. An instruction consists of an operation code (called ‘opcode’) and the address of the data (called
‘operand’), on which the opcode operates.

Q3. What is meant by low level and high level languages?


Ans. Programming languages that are machine dependent are called low level languages. For example, assembly
language is a low level language. On the other hand, programming languages that are machine
independent are called high level languages. Examples are BASIC, FORTRAN, C, ALGOL, COBOL,
etc.

Q4. Differentiate between a compiler/interpreter and an assembler.


Sr.No . Compiler/Interpreter Assembler
1 Debugging easier Debugging relatively tougher
2 Less efficient More efficient
3 Requires large memory space Requires less memory space

As an example, for gadget controls and traffic signals, assembly language programming is done because
programs in such cases are compact and not lengthy.
But for cases where large program lengths are a must, compilers/interpreters are used. For such a case, although
a large memory space is required, the advantage lies in very quick debugging.

Q5.Name the special purpose registers of 8085.

Ans. The special purpose registers used in 8085 microprocessor are:


1. Accumulator register (A),
2.Program counter register (PC),
3. Status (or Flag) register,
4.Stack pointer register (SP)
PRACTICAL: 3
1. Aim : Write an assembly language programming for Subtraction of two 8bit unsigned
nos. (a) Minuend is bigger than Subtrahend. (b) Result with provision of sign
indication

Input : (a) Output: (a)

7000 LDA 7100H


7003 MOV B, A
7004 LDA 7101H
7007 SUB B
7008 STA 7003H
700B HLT

Input : (b) Output: (b)

7000 MVI C,00H


7002 LXI D, (Minuend, Subtrahend) H
7005 LXI H, (Subtrahend, Minuend) H
7008 MOV A, L
7009 CMP H
700A JNC ##
700D XCHG
700E INR C
700F ## MOV A, L
7010 SUB H
7011 STA 7100H
7014 MOV A, C
7015 STA 7101H
7018 HLT
PRACTICAL: 4

Write an assembly language programming for addition of two 16bit unsigned nos.

Input:

7000 2A,00,71 LHLD 7100H ; Load first (lower 8 bit at 7100, Higher 8 bit at 7101) in H-L pair
7003 EB XCHG ; Shift to D-E pair
7004 2A,02,71 LHLD 7102H ; Load second (lower 8 bit at 7102, Higher 8 bit at 7103) in H-L pair
7007 19 DAD D ; add both no.
7008 22,04,71 SHLD 7104H ; Save the result (lower 8 bit at 7104, Higher 8 bit at 7105) in H-L pair
700B 76 HLT ; Stop the program.

Output:
PRACTICAL: 5

Write an assembly language programming for subtraction of two 16bit unsigned nos.

Input :

7000 LHLD 7100H


7003 XCHG
7004 LHLD 7102H
7007 MOV A, E
7008 SUB L
7009 MOV L, A
700A SBB H
700B MOV H, A
700C SHLD 7104H
700F HLT

Output :
PRACTICAL: 6

Write an assembly language programming for multiplication of two 8bit unsigned nos.

Input :

7000 LXI H, 7100H


7003 MOV E, M
7004 MVI D, 00H
7006 INX H
7007 MOV A, M
7008 LXI H, 0000H
700B MVI B, 08H
700D Multy DAD H
700E RAL
700F JNC SKIP
7012 DAD D
7013 SKIP DCR B
7014 JNZ Multy
7017 SHLD 7102H
701A HLT

Output:
PRACTICAL: 7

Write an assembly language programming for transferring a block of 5 unsigned nos


to a specified location.

Input :

7000 LXI D,7200H


7003 LXI H ,7100H
7006 MOV C, M
7007Loop INX H
7008 MOV A, M
7009 STAX D
700A INX D
700B DCR C
700C JNZ Loop
700F HLT

Output :
PRACTICAL: 8
Write an assembly language programming for a)smallest b)Largest no within an array
of 5nos.

Input : For (a)

2000 LDA [2500] [A]<-[2500]

2003 MOV B, A [B]<-[A]

2004 LDA 2501 [A]<-[2501]

2007 CMP B [A]<-[A]-[B]

2008 JC * [200C] jump carry

200B MOV A, B [A]<-[B]

200C STA [2502] [A]->[2502]

200F HLT STOP

Output : For (a)


Input : For (b)

2000 LXI H 2050 H←20, L←50

2003 MOV C, M C←M

2004 DCR C C←C-01

2005 INX H HL←HL+0001

2006 MOV A, M A←M

2007 INX H HL←HL+0001

2008 CMP M A-M

2009 JNC 200D If Carry Flag=0, goto 200D

200C MOV A, M A←M

200D DCR C C←C-1

200E JNZ 2007 If Zero Flag=0, goto 2007

2011 STA 3050 A→3050

2014 HLT

Output : For (b)


Oral Based Questions

Q.1: What is a stack? Why stack is used in a program?


Ans. A stack is a group of memory locations in the R/W memory. The stack is used to store
information temporarily during the execution of a program. Also the stack is used in subroutine calls to
store the return address. As an example, data generated at a certain point in a program may be needed
later in the program. This data is stored in the stack and retrieved when needed. Because the number of
general purpose registers (GPRs) in a microprocessor is limited–hence not all the temporary data can
be stored in them and this is where the stack plays its part.

Q2. How the stack is initialized? Is initialization of stack a must in a program?


Ans. The stack is initialized by a 16-bit register, called the stack pointer (SP) register. No, it is not a
must. If for programs for which any temporary data that are generated can be stored in GPRs and
which don’t require subroutine calls, there is no need to initialize the stack by the SP.

Q3. What type of memory is the stack? How the stack is initialized? Ans. Stack is a ‘last-in first-out’ or
LIFO type of memory. This means that data which is pushed last into stack is popped out of it first.
The stack is initialized by means of the stack pointer. The software instruction is like this: LXI SP,
0044.It means that the stack is initiated at the memory location 4400 by the stack pointer.

Q.4: Does 8085 have multiplication and division instructions?


Ans. No, 8085 does not have the above two instructions. It can neither multiply nor divide two 8-bit
numbers. The same are executed by the processor following the process of repetitive addition or
subtraction respectively.

Q.5: Explain maskable and non-maskable interrupts.


Ans. An interrupt which can be disabled by software means, is called a maskable interrupt. Thus an
interrupt which cannot be masked is an unaskable interrupt.

Q6. Which is the non-maskable interrupt for 8085?


Ans. TRAP interrupt is the non-maskable interrupt for 8085. It means that if an interrupt comes via
TRAP, 8085 will have to recognize the interrupt.

Q4. Do the interrupts of 8085 have priority?


Ans. Yes, the interrupts of 8085 have their priorities fixed—TRAP interrupt has the highest priority,
followed by RST 7.5, RST 6.5, RST 5.5 and lastly INTR.

Q5. What is meant by priority of interrupts?


Ans. It means that if 8085 is interrupted by more than one interrupt at the same time, the one which is
having highest priority will be serviced first, followed by the one(s) which is (are) having just next
priority and so on.For example, if 8085 is interrupted by RST 7.5, INTR and RST 5.5 at the same time,
then the sequence in which the interrupts are going to be serviced are as follows: RST7.5, RST 5.5 and
INTR respectively.
PRACTICAL: 9

Write an assembly language programming for arranging a string of two 5bit nos.in
a) Descending order b) Ascending order.

Input : For (a)

8000 21, 40, 80 START LXI H, Pointer to the IN-BUFFER


8040H

8003 16, 00 MVI D, 00H The D register is used as a flag register

8005 4E MOV C, M Initialize reg. C with data count

8006 0D DCR C Set Reg. C for comparison count

8007 23 INX H Pointing to the next location

8008 7E CHECK MOV A, M Get the number

8009 23 INX H Go to next location

800A BE CMP M Compare the contents of the current memory


location with the contents of the accumulator

800B D2, 14, JNC If (A) >= second byte, do not exchange
80 NEXTBYT

800E 46 MOV B, M Get second byte for exchange

800F 77 MOV M, A Store first byte in second location

8010 2B DCX H Point to first location

8011 70 MOV M, B Store second byte in first location


8012 23 INX H Get ready for next comparison

8013 16, 01 MVI D, 01H Load 1 in D as a remainder for exchange

8015 0D NEXTBYT DCR C Decrement comparison count

8016 C2, 08, JNZ CHECK If comparison count not 0, go back


80

8019 7A MOV A, D Get flag bit in A

801A 0F RRC Place flag bit D0in carry

801B DA, 00, JC START If flag is 1, exchange occurred


80

801E 76 HLT Terminate the program

Output : For (a)


Input: For (b)

8000 21, START LXI H, Pointer to the IN-BUFFER


40, 80 8040H

8003 16, 00 MVI D, 00H The D register is used as a flag register

8005 4E MOV C, M Initialize reg. C with data count

8006 0D DCR C Set Reg. C for comparison count

8007 23 INX H Pointing to the next location

8008 7E CHECK MOV A, M Get the number

8009 23 INX H Go to next location

800A BE CMP M Compare the contents of the current memory


location with the contents of the accumulator

800B DA, JC If (A) < second byte, do not exchange


14, 80 NEXTBYT

800E 46 MOV B, M Get second byte for exchange

800F 77 MOV M, A Store first byte in second location

8010 2B DCX H Point to first location

8011 70 MOV M, B Store second byte in first location

8012 23 INX H Get ready for next comparison

8013 16, 01 MVI D, 01H Load 1 in D as a remainder for exchange

8015 0D NEXTBYT DCR C Decrement comparison count


8016 C2, JNZ If comparison count not 0, go back
08, 80 CHECK

8019 7A MOV A, D Get flag bit in A

801A 0F RRC Place flag bit D0 in carry

801B DA, JC START If flag is 1, exchange occurred


00, 80

801E 76 HLT Terminate the program

Output: For (b)


PRACTICAL: 10
To write a assembly language program to multiply two8-bit numbers by using-8085
micro-processor kit.

Input :

2000 LHLD 2050 H←2051, L←2050

2003 XCHG H↔D, L↔E

2004 MOV C, D C←D

2005 MVI D 00 D←00

2007 LXI H 0000 H←00, L←00

200A DAD D HL←HL+DE

200B DCR C C←C-1

200C JNZ 200A If Zero Flag=0, goto 200A

200F SHLD 3050 H→3051, L→3050

2012 HLT

• Explanation – Registers used: A, H, L, C, D, E


1. LHLD 2050 loads content of 2051 in H and content of 2050 in L
2. XCHG exchanges contents of H with D and contents of L with E
3. MOV C, D copies content of D in C
4. MVI D 00 assigns 00 to D
5. LXI H 0000 assigns 00 to H and 00 to L
6. DAD D adds HL and DE and assigns the result to HL
7. DCR C decrements C by 1
8. JNZ 200A jumps program counter to 200A if zero flag = 0
9. SHLD stores value of H at memory location 3051 and L at 3050
10. HLT stops executing the program and halts any further execution
PRACTICAL: 11

Write an assembly language code in GNUsim8085 to store numbers in reverse order


in memory location.

Input :

2000 LDA 2050 A <- M[2050]

2003 RLC Rotate content of accumulator left by 1 bit

2004 RLC Rotate content of accumulator left by 1 bit

2005 RLC Rotate content of accumulator left by 1 bit

2006 RLC Rotate content of accumulator left by 1 bit

2007 STA 3050 M[2050] <- A

200A HLT END

Explanation – Register A used:

1. LDA 2050: load value of memory location 2050 in Accumulator A.


2. RLC: Rotate content of accumulator left by 1 bit
3. RLC: Rotate content of accumulator left by 1 bit
4. RLC: Rotate content of accumulator left by 1 bit
5. RLC: Rotate content of accumulator left by 1 bit
6. STA 3050: store content of A in memory location 3050.
7. HLT: stops executing the program and halts any further execution.

Output :
PRACTICAL: 12

Implement Booth’s Algorithm.

Flow Chart :

Numerical Example :
PRACTICAL: 13

Write an assembly language code in GNUsim8085 to implement arithmetic instruction.

Arithmetic Instructions are the instructions which perform basic arithmetic operations
such as addition, subtraction and a few more. In 8085 microprocessor, the
destination operand is generally the accumulator.

Opcode Operand Description


ADD R,M Add register or memory to accumulator

ADC R,M Add register to accumulator with carry

ADI 8 bit data Add immediate to accumulator

ACI 8 bit data Add immediate to accumulator with carry

DAD Reg. pair Add register pair to H and L registers

SUB R,M Subtract register or memory from accumulator

SBB R,M Subtract source and borrow from accumulator

SUI 8 bit data Subtract immediate from accumulator

SBI 8 bit data Subtract immediate from accumulator with borrow

INR R,M Increment register or memory by 1

INX R Increment register pair by 1

DCR R,M Decrement register or memory by 1

DCX R Decrement register pair by 1

DAA None Decimal adjust accumulator


PRACTICAL: 14
Write an assembly language code in GNUsim8085 to find the factorial of a number.

Input:

2000H Data Data Byte

2001H Result Result of factorial

2002H LXI H, 2000H Load data from memory

2005H MOV B, M Load data to B register

2006H MVI D, 01H Set D register with 1

2008H FACTORIAL CALL MULTIPLY Subroutine call for multiplication

200BH DCR B Decrement B

200CH JNZ FACTORIAL Call factorial till B becomes 0

200FH INX H Increment memory

2010H MOV M, D Store result in memory

2011H HLT Halt

2100H MULTIPLY MOV E, B Transfer contents of B to C

2101H MVI A, 00H Clear accumulator to store result

2103H MULTIPLYLOOP ADD D Add contents of D to A

2104H DCR E Decrement E

JNZ
2105H MULTIPLYLOOP Repeated addition

2108H MOV D, A Transfer contents of A to D

2109H RET Return from subroutine


Algorithm –
1. Load the data into register B
2. To start multiplication set D to 01H
3. Jump to step 7
4. Decrements B to multiply previous number
5. Jump to step 3 till value of B>0
6. Take memory pointer to next location and store result
7. Load E with contents of B and clear accumulator
8. Repeatedly add contents of D to accumulator E times
9. Store accumulator content to D
10. Go to step 4

Explanation –
1. First set register B with data.
2. Set register D with data by calling MULTIPLY subroutine one time.
3. Decrement B and add D to itself B times by calling MULTIPLY subroutine
as 4*3 is equivalent to 4+4+4 (i.e., 3 times).
4. Repeat the above step till B reaches 0 and then exit the program.
5. The result is obtained in D register which is stored in memory
PRACTICAL: 15

Write an assembly language code in GNUsim8085 to implement logical instructions.

Opcode Operand Description


CMP R,M Compare the register or memory with the accumulator

CPI 8 bit data Compare immediate with the accumulator

ANA R,M Logical AND register or memory with the accumulator

ANI 8 bit data Logical AND immediate with the accumulator

XRA R,M Exclusive OR register or memory with the accumulator

XRI 8 bit data Exclusive OR immediate with the accumulator

ORA R,M Logical OR register or memory with the accumulator

ORI 8 bit data Logical OR immediate with the accumulator

RLC None Rotate the accumulator left

RRC None Rotate the accumulator right

RAL None Rotate the accumulator left through carry

RAR None Rotate the accumulator right through carry

CMA None Complement accumulator

CMC None Complement carry

STC None Set Carry


PRACTICAL: 16

Design ALU using Logisim.


Theory:

LogiSim is a LOGic SIMulator. When learning computer architecture and logic circuits, one needs a
real-world, graphical example of what you are studying. Text and diagrams only go so far. A helpful
tool for designing and simulating logic circuits is Logisim.

The explorer pane contains all of the elements needed to create circuits. For example, gates, plexers
etc. In order to add an element from the explorer pane, you select the item in the pane. Next, you click
on the canvas to drop the element onto your design. Now to add an element from the explorer pane,
you need to select any item in the pane. Next, you click on the canvas to drop the element onto your
design. Suppose, we choose and drop an AND gate onto the canvas. Explorer pane>>gates>>AND
gate The attributes pane will get activated i.e. will have some options. The figure here shows the AND
gate into canvas and also attribute along with options.
We can change the direction the gate faces (east, west, north, south), or the number of data bits (the
default is 1). As you build circuits, you will be changing the attributes of your elements here. Changing
Values in Circuits In the toolbar, you'll notice a little hand icon (shown in Figure). This icon is used to
change values in circuits. This is how you test your circuits.

Code :
<?xml
version="1.0"
encoding="UTF-8"
standalone="no"?>
<project source="2.7.1" version="1.0">
This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/).
<lib desc="#Wiring" name="0"/>
<lib desc="#Gates" name="1"/>
<lib desc="#Plexers" name="2"/>
<lib desc="#Arithmetic" name="3"/>
<lib desc="#Memory" name="4"/>
<lib desc="#I/O" name="5"/>
<lib desc="#Base" name="6">
<tool name="Text Tool">
<a name="text" val=""/>
<a name="font" val="SansSerif plain 12"/>
<a name="halign" val="center"/>
<a name="valign" val="base"/>
</tool>
</lib>
<main name="main"/>
<options>
<a name="gateUndefined" val="ignore"/>
<a name="simlimit" val="1000"/>
<a name="simrand" val="0"/>
</options>
<mappings>
<tool lib="6" map="Button2" name="Menu Tool"/>
<tool lib="6" map="Button3" name="Menu Tool"/>
<tool lib="6" map="Ctrl Button1" name="Menu Tool"/>
</mappings>
<toolbar>
<tool lib="6" name="Poke Tool"/>
<tool lib="6" name="Edit Tool"/>
<tool lib="6" name="Text Tool">
<a name="text" val=""/>
<a name="font" val="SansSerif plain 12"/>
<a name="halign" val="center"/>
<a name="valign" val="base"/>
</tool>
<sep/>
<tool lib="0" name="Pin">
<a name="width" val="4"/>
<a name="tristate" val="false"/>
</tool>
<tool lib="0" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="width" val="4"/>
<a name="labelloc" val="east"/>
</tool>
<tool lib="1" name="NOT Gate"/>
<tool lib="1" name="AND Gate"/>
<tool lib="1" name="OR Gate"/>
</toolbar>
<circuit name="main">
<a name="circuit" val="main"/>
<a name="clabel" val=""/>
<a name="clabelup" val="east"/>
<a name="clabelfont" val="SansSerif plain 12"/>
<wire from="(320,270)" to="(380,270)"/>
<wire from="(400,320)" to="(460,320)"/>
<wire from="(400,220)" to="(460,220)"/>
<wire from="(380,270)" to="(380,340)"/>
<wire from="(670,290)" to="(720,290)"/>
<wire from="(670,300)" to="(720,300)"/>
<wire from="(500,510)" to="(690,510)"/>
<wire from="(270,520)" to="(460,520)"/>
<wire from="(300,220)" to="(350,220)"/>
<wire from="(270,270)" to="(320,270)"/>
<wire from="(350,220)" to="(400,220)"/>
<wire from="(500,420)" to="(680,420)"/>
<wire from="(740,420)" to="(800,420)"/>
<wire from="(160,270)" to="(270,270)"/>
<wire from="(500,230)" to="(670,230)"/>
<wire from="(500,330)" to="(670,330)"/>
<wire from="(680,310)" to="(720,310)"/>
<wire from="(800,420)" to="(800,450)"/>
<wire from="(670,300)" to="(670,330)"/>
<wire from="(350,410)" to="(460,410)"/>
<wire from="(420,240)" to="(420,270)"/>
<wire from="(300,220)" to="(300,500)"/>
<wire from="(380,270)" to="(420,270)"/>
<wire from="(420,240)" to="(460,240)"/>
<wire from="(400,220)" to="(400,320)"/>
<wire from="(320,270)" to="(320,430)"/>
<wire from="(300,500)" to="(460,500)"/>
<wire from="(680,310)" to="(680,420)"/>
<wire from="(690,320)" to="(720,320)"/>
<wire from="(770,450)" to="(800,450)"/>
<wire from="(760,330)" to="(920,330)"/>
<wire from="(320,430)" to="(460,430)"/>
<wire from="(690,320)" to="(690,510)"/>
<wire from="(380,340)" to="(460,340)"/>
<wire from="(160,220)" to="(300,220)"/>
<wire from="(670,230)" to="(670,290)"/>
<wire from="(740,370)" to="(740,420)"/>
<wire from="(350,220)" to="(350,410)"/>
<wire from="(270,270)" to="(270,520)"/>
<comp lib="3" loc="(500,420)" name="Multiplier">
<a name="width" val="4"/>
</comp>
<comp lib="3" loc="(500,510)" name="Divider">
<a name="width" val="4"/>
</comp>
<comp lib="2" loc="(760,330)" name="Multiplexer">
<a name="select" val="3"/>
<a name="width" val="4"/>
</comp>
<comp lib="0" loc="(160,270)" name="Pin">
<a name="width" val="4"/>
<a name="tristate" val="false"/>
</comp>
<comp lib="3" loc="(500,330)" name="Subtractor">
<a name="width" val="4"/>
</comp>
<comp lib="6" loc="(460,368)" name="Text">
<a name="text" val="SUBTRACTOR"/>
</comp>
<comp lib="0" loc="(770,450)" name="Pin">
<a name="width" val="3"/>
<a name="tristate" val="false"/>
</comp>
<comp lib="0" loc="(160,220)" name="Pin">
<a name="width" val="4"/>
<a name="tristate" val="false"/>
</comp>
<comp lib="0" loc="(920,330)" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="width" val="4"/>
<a name="labelloc" val="east"/>
</comp>
<comp lib="6" loc="(88,217)" name="Text">
<a name="text" val="A"/>
</comp>
<comp lib="6" loc="(471,458)" name="Text">
<a name="text" val="MULTIPLIER"/>
</comp>
<comp lib="6" loc="(742,487)" name="Text">
<a name="text" val="MULTIPLEXER BITS"/>
</comp>
<comp lib="6" loc="(465,552)" name="Text">
<a name="text" val="DIVIDER"/>
</comp>
<comp lib="6" loc="(940,368)" name="Text">
<a name="text" val="OUTPUT"/>
</comp>
<comp lib="6" loc="(774,283)" name="Text">
<a name="text" val="8:1 MULTIPLEXER"/>
</comp>
<comp lib="3" loc="(500,230)" name="Adder">
<a name="width" val="4"/>
</comp>
<comp lib="6" loc="(469,269)" name="Text">
<a name="text" val="ADDER"/>
</comp>
<comp lib="6" loc="(93,272)" name="Text">
<a name="text" val="B"/>
</comp>
</circuit>
</project>
PRACTICAL: 17

Implement 16-bit single-cycle MIPS processor in Verilog HDL.

Verilog, standardized as IEEE 1364, is a hardware description language (HDL) used to


model electronic systems. It is most commonly used in the design and verification of digital
circuits at the register-transfer level of abstraction. It is also used in the verification of analog
circuits and mixed-signal circuits, as well as in the design of genetic circuits.

HDL simulators are software packages that simulate expressions written in one of
the hardware description languages, such as VHDL, Verilog, SystemVerilog.
This page is intended to list current and historical HDL simulators, accelerators, emulators,
etc.

In this Verilog project, basic blocks in digital logic design such as D-Flip-Flop, adders, ALU,
registers, memory, multiplexers, decoders, counters, etc. are implemented in Verilog HDL
for beginners.

Verilog code for single-cycle MIPS processor:


//fpga4student.com: FPGA projects, Verilog projects, VHDL
projects
// Verilog project: Verilog code for 16-bit MIPS Processor
// Verilog code for 16 bit single cycle MIPS CPU
module mips_16( input clk,reset,
output[15:0] pc_out, alu_result
//,reg3,reg4
);
reg[15:0] pc_current;
wire signed[15:0] pc_next,pc2;
wire [15:0] instr;
wire[1:0] reg_dst,mem_to_reg,alu_op;
wire jump,branch,mem_read,mem_write,alu_src,reg_write
;
wire [2:0] reg_write_dest;
wire [15:0] reg_write_data;
wire [2:0] reg_read_addr_1;
wire [15:0] reg_read_data_1;
wire [2:0] reg_read_addr_2;
wire [15:0] reg_read_data_2;
wire [15:0] sign_ext_im,read_data2,zero_ext_im,imm_ext;
wire JRControl;
wire [2:0] ALU_Control;
wire [15:0] ALU_out;
wire zero_flag;
wire signed[15:0] im_shift_1, PC_j, PC_beq,
PC_4beq,PC_4beqj,PC_jr;
wire beq_control;
wire [14:0] jump_shift_1;
wire [15:0]mem_read_data;
wire [15:0] no_sign_ext;
wire sign_or_zero;
// PC
always @(posedge clk or posedge reset)
begin
if(reset)
pc_current <= 16'd0;
else
pc_current <= pc_next;
end
// PC + 2
assign pc2 = pc_current + 16'd2;
// instruction memory
instr_mem
instrucion_memory(.pc(pc_current),.instruction(instr));
// jump shift left 1
assign jump_shift_1 = {instr[13:0],1'b0};
// control unit
control
control_unit(.reset(reset),.opcode(instr[15:13]),.reg_dst(r
eg_dst)

,.mem_to_reg(mem_to_reg),.alu_op(alu_op),.jump(jump),.branc
h(branch),.mem_read(mem_read),

.mem_write(mem_write),.alu_src(alu_src),.reg_write(reg_writ
e),.sign_or_zero(sign_or_zero));
// multiplexer regdest
assign reg_write_dest = (reg_dst==2'b10) ? 3'b111:
((reg_dst==2'b01) ? instr[6:4] :instr[9:7]);
// register file
assign reg_read_addr_1 = instr[12:10];
assign reg_read_addr_2 = instr[9:7];
register_file
reg_file(.clk(clk),.rst(reset),.reg_write_en(reg_write),
.reg_write_dest(reg_write_dest),
.reg_write_data(reg_write_data),
.reg_read_addr_1(reg_read_addr_1),
.reg_read_data_1(reg_read_data_1),
.reg_read_addr_2(reg_read_addr_2),
.reg_read_data_2(reg_read_data_2));
//.reg3(reg3),
//.reg4(reg4));
// sign extend
assign sign_ext_im = {{9{instr[6]}},instr[6:0]};
assign zero_ext_im = {{9{1'b0}},instr[6:0]};
assign imm_ext = (sign_or_zero==1'b1) ? sign_ext_im :
zero_ext_im;
// JR control
JR_Control
JRControl_unit(.alu_op(alu_op),.funct(instr[3:0]),.JRContro
l(JRControl));
// ALU control unit
ALUControl
ALU_Control_unit(.ALUOp(alu_op),.Function(instr[3:0]),.ALU_
Control(ALU_Control));
// multiplexer alu_src
assign read_data2 = (alu_src==1'b1) ? imm_ext :
reg_read_data_2;
// ALU
alu
alu_unit(.a(reg_read_data_1),.b(read_data2),.alu_control(AL
U_Control),.result(ALU_out),.zero(zero_flag));
// immediate shift 1
assign im_shift_1 = {imm_ext[14:0],1'b0};
//
assign no_sign_ext = ~(im_shift_1) + 1'b1;
// PC beq add
assign PC_beq = (im_shift_1[15] == 1'b1) ? (pc2 -
no_sign_ext): (pc2 +im_shift_1);
// beq control
assign beq_control = branch & zero_flag;
// PC_beq
assign PC_4beq = (beq_control==1'b1) ? PC_beq : pc2;
// PC_j
assign PC_j = {pc2[15],jump_shift_1};
// PC_4beqj
assign PC_4beqj = (jump == 1'b1) ? PC_j : PC_4beq;
// PC_jr
assign PC_jr = reg_read_data_1;
// PC_next
assign pc_next = (JRControl==1'b1) ? PC_jr : PC_4beqj;
// data memory
data_memory datamem(.clk(clk),.mem_access_addr(ALU_out),

.mem_write_data(reg_read_data_2),.mem_write_en(mem_write),.
mem_read(mem_read),
.mem_read_data(mem_read_data));
// write back
assign reg_write_data = (mem_to_reg == 2'b10) ?
pc2:((mem_to_reg == 2'b01)? mem_read_data: ALU_out);
// output
assign pc_out = pc_current;
assign alu_result = ALU_out;
endmodule
PRACTICAL: 18

Case study of traffic signal controller system. (Study only)

You might also like