Sunteți pe pagina 1din 11

MICROPROCESSORS

Design of Experiment

8-bit 2’s Complement Calculator

Name:

BASILIO, JOHN KENNETH C.

PANTOJA, CHRISTIAN ROYD E.

SANGALANG, GABRIEL CARLO P.

Course/Section: COE121L/E01

Group No.: 6

Date of Submission: August 07, 2020

Engr. Isagani Villamor

Professor
Objectives

 The objective of this project is to create a program that would complement its
input.
 The program should be able to take an 8-bit input and complement the input with
2’s complement.

Design of Experiment

8 – bit 2’s Complement Calculator

Learning Objectives:

1. Able to create design of experiment with EdSim51 simulator.


2. Integrate 8 – bit 2’s complement concept to EdSim51 simulation.
3. Apply operating commands learned from previous experiments.
4. Demonstrate 8051 microcontroller operates with I/O interfaces.

DISCUSSION

Binary Number System is one of the most recognizable types of number representation
technique that is commonly used in digital system. In the binary system wherein there
are only two digit values, particularly 0 (off state) and 1 (on state) which represented by
any device that only operates in two operating state condition.

There are two types used in complementing binary numbers: (i) 1’s complement and 2’s
complement. In 1’s complement in binary system, it will just invert the given binary
number whereas to get the 2’s complement is simply add 1 to the inverted given value.
Implementation of a 4-bit 2’s complement number system is shown below.
Figure 1. Implementation of a 4-bit 2’s complement number system

There are various functions of 2’s complement of binary numbers such as


demonstrating signed binary number representation and several arithmetic operations
for binary numbers which includes addition, subtractions, etc. 2’s complement number
representation is mostly used for signed numbers on modern computers. It allows
computer to add and subtract numbers using the same operations with 2’s complement
notation: (i) a fixed number of bits are used to represent input, (ii) sign bit are the most
significant bit, and (iii) represent both positive numbers and negative numbers.

Signed complement forms of binary number system can either use 1’s complement or
2’s complement as it permit representation of negative numbers. The method of 2’s
complement arithmetic are mostly used in computers in handling negative numbers.

Figure 2. 5 bits register representation

In 2’s complement inversion and adding one works which shows mathematical shortcut
of a straight forward computation. It is a method to represent negative binary numbers
in a signed binary numbers. The positive numbers will be the same as the unsigned
binary number representation whereas different for negative number as its resulted to
inaccurate due to its corresponding positive equivalent value in zero. The advantage of
2’s complement is it doesn’t result to double-zero problems. The arithmetic operations
will be relatively easier to perform when the numbers is represented in 2’s complement
format.

Non-negative integers will start with ‘0’ and will have as many leading zero depending to
the required number of bits. Negative integers will always begin with ‘1’. 2’s complement
numbers are same with unsigned binary numbers except for the most significant bit
position as it has a weight of −2 N−1instead of 2 N−1 as it will overcomes shortcomings
from signed magnitude numbers. No overflow occurrence is when the value of the bit
carried into the most significant bit is equal to the value carried out of the most
significant bit. Occurrence of overflow means that the value of the bit carried into the
most significant bit is not equal to the bit carried out.

Table 1. 4-bit 2’s complement values

MATERIALS
 EDSIM51 Dynamic Interface is the software used for this project. The EdSim51 is
a software of GUI that simulates three microcontroller concepts which are the
memory read cycle, memory write cycle and the Instruction execution cycle.
Basically it is a software based on a microcontroller which contains SSD, LED
displays, DC motor and such.

PROCEDURE

8-bit 2’s Complement Calculator

1. Launch the EdSim51DI IDE.


2. Click new in the EdSim51DI IDE.
3. Click New and encode the following instructions at the IDE (integrated
development environment). The starting address 0000H.

ORG 0000H ;initializing the starting address of the program

MAIN: ;start of the main program


CLR A ;clear the content of register Accumulator
CALL DELAY ; wait to clear
MOV A, P2 ; move data pointed by P2 to A
CPL A ;complement value of A
ADD A, #01H ;adding the contents of Accumulator with 01H. Destination A.
MOV P1, A ;move data pointed by P1 to A

DELAY: ;time delay


MOV R0, #20H ;loading register R0 with 20H
DJNZ R0, $ ;decrement R0 otherwise it will jump in $
RET ;return

END ;end of the program

4. To speed up the output. Click Update Frequency then value 100.


5. Save the program.
6. Assemble the program.
7. Press switches based on the given (See Q1).
8. Observe the output. Answer Questions

Note: when pressing switches, it will be in low state “0”.

QUESTIONS

Q1. Complete the table below. Run the program to fill in answers. Provide
illustrations

Given Input 2’s Complement Equivalent Number


10001000 01111000
10000111 01111001
10000110 01111010
00000101 11111011
00000100 11111100

Screenshot 1:
Screenshot 2:

Screenshot 3:

Screenshot 4:

Screenshot 5:

Q2. How were you able to identify the output? Explain.

The LED will show the 2’s complement. When the LED is on, it represents
0. When the LED is off, it represents 1. This is because LEDs are active
low. To display a high value, the corresponding LED is OFF. Otherwise,
the LED is ON. When inputting values, a pressed switch is considered 0
while a not pressed switch is 1.
Q3. In 2’s complement, what do all the positive numbers have in common?

In 2’s complement, all positive numbers begin with a 0.________________

Q4. What advantage does 2’s complement have over 1’s complement?

In 2’s complement there is only one way to represent 0 and it simplifies our
representation scheme.____________________________________________

Interpretation of Results
In this Project, the group created a program that would complement n 8-bit binary input

with the use of the 2’s complement. With the help of the Microcontroller simulator the

EDSIM51, we constructed a series of commands that would help aid the computation of

the 2’s complement of the input. Observing the opcodes, there were several commands

that were used similar to the experiments performed in the simulation. CPL, ADD and

MOV were some of the similar opcodes used in the simulation. The Opcodes were

placed in the IDE of the simulation which was there it was processed and debug by the

simulation. The software would detect the problems in the codes and misplaced

opcodes or declarations. The input is then placed in the LED in the lower left of the

simulation as observed in the screenshot of the program. The input is placed after the

program starts. Starting the program, it will compile it’s instructions and run. There the

input is then placed on the LED. The Seven-segment Display would then project the

output of the program as seen on the screenshot. The output is the 2’s complement of

the input. In changing the values of the input simply place the desired value on the

lower left of the program where the led buttons are located. It would then be displayed

on the SSD.

CONCLUSION
After performing the design experiment, we therefore conclude that:
o Both 1's complement and 2's complement are binary representations of
signed quantities where the most significant bit on the leftmost is the sign bit.

o 2’s complement is essential especially in negative numbers representation in


the binary system as there is only two numbers used 1 and 0 or the signed
notation. A number with a leading 1 is negative while with leading 0 denotes a
positive value.

o 2’s complement comes from the fact that a negative number is a 2’s
complement of a positive number.

o 2’s complement is mainly used to avoid multiple representation of 0 and avoid


keeping track of carry bit in case of an overflow.

REFERENCE

- https://www.tutorialspoint.com/two-s-complement
- https://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html
- https://www.sciencedirect.com/topics/computer-science/twos-complement-number
- https://www.ele.uri.edu/courses/ele447/proj_pages/divid/twos.html
- https://www.edsim51.com
- http://www.keil.com/support/man/docs/is51/is51_opcodes.htm
-

S-ar putea să vă placă și