You are on page 1of 13

Bangladesh University of Engineering and

Technology

Course No.: EEE 415

Implementation of a 4 Bit Computer in VerilogHDL

Submitted By:
Rifat Bin Rashid
ID: 1606117
Section: B
Level: 4 Term: 1
Instruction set:
My ID number is: 1606117
So, for my roll number, the instruction set is:
Explanation of instruction set:
Add:
Add instruction is used to add two data. This instruction has the
following syntax:
ADD destination, source
In code:
0: begin // ADD
{CF,A}=A_in+B_in;
ZF = (A==0)? 1:0;
SF = (A<0)? 1:0;
end

Here, data input given in A_in and B_in is being added and stored in ‘A’
and the carry flag is being updated if this addition has any carry out.
Similarly, zero flag and sign flag are also being updated depending on
the result of addition.

Sub:
This operation is quite similar to the add operation. This instruction also
has the similar syntax:
sub destination, source

XCHG B, A:
This instruction is for swapping the value of two data.
In code:
2:begin // XCHG B,A
X = A_in;
A = B_in;
B= X;
ZF = (A==0)? 1:0;
SF = (A<0)? 1:0;

MOV A,[ADDRESS]:
The data value of a particular memory location is being transferred to
A.
Code:
3:begin // MOV A,[ADDRESS]
A = memory[address];
ZF = (A==0)? 1:0;
SF = (A<0)? 1:0;
End

MOV [ADDRESS],B:
The data value given in B_in is being transferred to specific memory
location.
Code:
4:begin // MOV_ADDRESS()_B
memory[address]=B_in;
end
OUT A:
The value given in A_in is transferred in output port.
Code:
5:begin // OUT A
out=A_in;
end

TEST B, A:
Here, bitwise and operation is being performed without altering the
value of the data input itself.
Code:
6:begin // TEST B,A
X=A_in & B_in;
ZF = (X==0)? 1:0;
end

OR B, [ADDRESS]:
Here, bitwise or operation is being performed between B_in and the
data value of a particular memory location.
Code:
7:begin // OR B,[ADDRESS]
B = B_in | memory[address];
ZF = (B==0)? 1:0;
end
JNZ ADDRESS:
Here the instruction pointer is jumping to a particular address if the
result of previous operation is zero.
Code:
8:begin // JNZ_ADDRESS()
if(!ZF)
AP = address;
end

JMP ADDRESS:
Here the instruction pointer is jumping to a particular address
unconditionally.
Code:
9:begin // JMP ADDRESS
AP = address;
End

PUSH A:
Here the data value of A_in is being pushed in the stack segment. we
can observe the pushed value from the output reg: ‘Stack_Seg’. In
addition, the value of stack pointer is being increased by 1 to be ready
for a new push operation.
Code:
11:begin // PUSH A
stack[SP]=A_in;
Stack_Seg = stack[SP];
SP = SP+1;
end

POP A:
The data value stored in stack segment is now being popped on ‘A’. In
addition, the value of stack pointer is being decreased by 1 to indicate
the stack pointer is now empty in this particular location.
Code:
12:begin // POP A
SP = SP-1;
A=stack[SP];
Stack_Seg = 0;
ZF = (A==0)? 1:0;
SF = (A<0)? 1:0;
end

CALL ADDRESS:
When a particular address is being called (in case of a procedure or
jump operation), program is executing the instruction in that address
by pointing the instruction pointer to this particular address location.
Code:
13:begin // CALL ADDRESS
stack[SP] = AP;
AP = address;
SP = SP + 1;
end

Ret:
At the end of a procedure, program is returning now from the very next
line where the procedure was called.
Code:
14:begin // RET
SP = SP - 1;
AP = stack[SP];
end
Features:
Sign flag:
Sign flag is basically the MSB of a data value. So, SF=1 for a negative
number and SF=0 for as positive number.

Carry flag:
This flag is used to contain the additional bit of an operation. For
example, when two four-bit number is added, the result of the addition
can be of maximum 5 bit. Here the carry flag is used to store the extra
carry out bit.

Zero flag:
When the value of an operation becomes zero, zero flag is updated. In
this case, ZF=1, otherwise ZF=0.

Stack memory:
Stack memory is necessary for the push pop operation for storing a
particular data value temporarily. In our code, the stack memory has
total number of fifteen 4-bit value storage capacity.
Output waveform:
Output waveform is presented here for various operation.

ADD:

Here A_in=5 and B_in=2. The result of their addition (7) is being
stored in A.

Sub:

Here A_in=5 and B_in=2. The result of their subtraction (3) is being
stored in A.
XCHG:

OUT A:

TEST B, A:
Here, bitwise and operation is being performed without altering the
value of the data input itself. A_in=9 (1001) and B_in= 6(0110), so the
result of their bitwise and operation will be zero. The r=exact result is
indicated here by updating ZF=1.

PUSH A:

Here, the value of A_in (5[0101]) is being stored in the stack segment.
Microsoft stream link:

https://web.microsoftstream.com/video/fa3cc84c-f3c9-4a03-ba80-
99c06dee3591

You might also like