Coded Hex Calculator With signed - PowerPoint PPT Presentation

About This Presentation
Title:

Coded Hex Calculator With signed

Description:

XOR 80 AND /n = ((A xor B) and 80h) -- To check wheather only /one of them is negative ... 0= R SWAP 0= /CHECKS WHEATHER QUOTIENT IS ZERO OR NOT R SWAP R R AND ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 21
Provided by: oakl
Category:

less

Transcript and Presenter's Notes

Title: Coded Hex Calculator With signed


1
Coded Hex Calculator With signed Unsigned
Caluclations
Project Done By Apurva Patel Vrajesh
Patel Swapna Kalakonda
2
Introduction
  • The purpose of this project is to build a coded
    Hex Calculator that does the following
    operations

- Multiply
-Square of a number
- Addions of signed and Unsigned Numbers
- Subtractions of signed and Unsigned Numbers
- Division
- Signed Division
3
Multiplication
case 1 - Multiplying two negative numbers--gt
will give the answer in positve so we will take
the abs of the two numbers and then multiply
the abs function (Absolute Value Function)
-This function will take the 2s complement of
the number if the number is negative (signed)
case 2 If a positive number is multiplied by a
negative number then for sure the ans is going to
be negative. For the ans to be negative we
will take the abs of that negative number and
then do a normal multiply and to show that the
ans is negative will turn on the LED showing the
negative sign.
case 3 when both are positive then we will do
the regular multiply
4
Sigmul.Whp
SM (A B -- (AB)) OVER OVER /2Dup
A B A B XOR 80 AND /n ((A xor B) and
80h) -- To check wheather only
/one of them is negative DUP
/A B n n gtR /A B n ?ABS
/call to the routine ?ABS to take the
absolute /values of
negative numbers either A or B or
/both /call to the
normal unsigned multiplication routine
/for multiplying / C
AB Rgt /C n IF
/if n 1 the answer is negative indicated
by /pushing 80h into 80 LD!
/ LED register THEN
5
Square
This routine multiplies the input number by
itself. The following is the whyp file for
square. SQUARE (A -- AA ) DUP
/ A A /call to unsigned
multiplication routine for multiplying
AA
6
Unsigned Division
How to do Unsigned Division to get 16-bit
Quotient and a 8-bit remainder.
In order to get a 16-bit quotient we need to
carry out the normal division two times.
Each time we will get a 8-bit quotient. This
routine will not give us an overflow unless a
number is divided by 00h.
7
unsigndiv.whp
MU/MOD (NL NH D -- R Q) /THIS ROUTINE DIVIDES
/16-BIT NUMERATOR
WITH /8-BIT
DENOMINATOR TO
/GIVE 8-BIT QIUOTIENT AND
/8-BIT REMAINDER -ROT /D NL
NH DIV DIV DIV DIV DIV DIV DIV DIV
ROT_DROP_SWAP /R Q UM/MOD (NL NH D -- R QL
QH) gtR 00 R_at_ /NL NH 00 D D
MU/MOD /R QH D Rgt
/R QH D SWAP /R D QH gtR /R
D QH MU/MOD /R2 QL
QH Rgt /R2 QL QH
8
Signed
Division
This takes in a 16-bit signed numerator and an
8-bit Denominator Therefore, the sign numbers can
be broken down into the following categories 1.
0000h to 7FFFh --gt Positive numbers 2. 8000h to
FFFFh --gt Negative numbers The following are the
cases for signed division
Divident Divisor Quotient Remainder
Negative Negative Positive Negative Negative
Positive Negative Negative Positive
Negative Negative Positive Positive Positive
Positive Positive
9
Signdiv.whp
DIVIDE (NL NH D -- R QL QH) OVER OVER AND
/NL NH D NH D 80 AND IF
/NHlt0 Dlt0 --gt QLQHgt0 AND Rlt0 ABS
-ROT DABS /D NL NH ROT UM/MOD /R
QL QH WAITBTN3 /R QL QH DROP DROP
0 /R IF /IF R 0 NO
NEED TO SHOW NEGATIVE SIGN 00 LD!
/ELSE LIGHT UP THE SIG LED ELSE 80 LD!
/SHOWS REMAINDER IS NEGATIVE THEN
ELSE /EITHER NUMERATOR OR DENOMINTOR
lt 0 OR BOTH gt 0 0lt IF
/Dlt0 AND NLNH gt0 --gt QLQHlt0 AND Rgt0
ABS /NL NH D UM/MOD /R QL
QH 0 gtR SWAP 0 /CHECKS WHEATHER
QUOTIENT IS ZERO OR NOT gtR SWAP Rgt Rgt AND

10
Cont...
IF /IF QUOTIENT IS ZERO NO NEED TO SHOW
THE /NEGATIVE SIGN 00
LD! ELSE 80 LD! THEN
WAITBTN3 00 LD! /R QL QH DROP
DROP /R ELSE
-ROT /D NL NH 0lt /CHECKS
WHEATHER NUMERATOR lt 0 IF /Dgt0
AND NLNHlt0 --gt Rlt0 AND QLQHlt0 DABS
/D NLNH ROT UM/MOD /R QL QH
0 gtR SWAP 0 /CHECKS WHEATHER QUOTIENT IS ZERO
OR NOT gtR SWAP Rgt Rgt AND
11
Cont...
IF /IF QUOTIENT IS ZERO NO NEED TO
SHOW THE /NEGATIVE SIGN
00 LD! ELSE 80 LD!
THEN WAITBTN3 /R QL QH DROP
DROP /R 0 IF
/CHECKS WHEATHER QUOTIENT IS ZERO OR NOT
00 LD! ELSE 80 LD!
THEN ELSE /Dgt0 NLNHgt0 --gt Rgt0
QLQHgt0 ROT /NL NH D UM/MOD
/R QL QH WAITBTN3 /R QL QH DROP DROP
/R THEN THEN THEN
12
Signed
Subtraction
Case 1 Subtracting when both the numbers are
negative subcase 1 if BgtA then get a positive
answer else get a negative answer
Case 2 When one of A or B is a negative
number subcase 1 if A ve and B -ve then
ans A B else if A -ve and B is ve then
ans -(AB)
Case 3 when both are positive ans A-B and the
ans is postive or neg depending on the magnitude
of A and B
13
Signsub.whp
S- (A B -- A-B) 0lt
/checks wheather Blt0 IF
/Blt0 SWAP
/B A 0lt
/checks wheather Alt0 IF
/Alt0 and Blt0 - 0lt
/ C B-A IF
/checks wheather Clt0 ABS
ELSE 80 LD! THEN ELSE
/Blt0 and Agt0
SWAP ABS /C A-(-B) 0lt
/if Clt0 It is a
overflow IF FF LD!
/Indicates a overflow THEN THEN
ELSE SWAP 0lt
IF /Bgt0 and Alt0
ABS /C -A-B 0lt
/If C is negative
indicates a overflow
/else answer is negative and
2'scomplement
/of C
14
Cont...
IF FF LD! ELSE
80 LD! THEN ELSE
/Agt0 and Bgt0 SWAP -
/C A - B 0lt
IF /if BgtA then
answer is negative and 2'scomplement of ABS
/of C 80 LD! THEN
THEN THEN
15
Changes Made to The W8Y controller
Changed from Mux2g to mux 3g
Input from 16x8 Dpram
N2
ALU4
Output Y2 of ALU4
16
Whyp Words Added to W8Y controller
mpp Carries out the multiplication of the
numbers in the data stack when
called 8 times divide carries out the
division of the numbers in the
data stack when called 8 times to leave a 8-bit
quotient and 8-bit remainder
ABS takes the absoloute value of the number in
T-Reg DABS Takes the 2s complement of a
16-bit number and leaves the
higher 8-bit in T-Reg and the lower
8-bits in N-Reg
17
Users Guide
1. First enter the code for the operation to be
carried out. Project 1 operations hex code
operation 01h signed subtraction 02h unsigned
multiplication 03h Square 04h signed
multiplication Project 2 operations hex
code operations 01h unsigned division 02h
signed division If the entered hex code is
different from the above codes all the LEDs will
Light up indicating a NULL operation. 2. Enter
the required hex values
18
Cont user guide
For division enter the lower 8-bits of
numerator first and followed by higher 8-bits
followed by the denominator Press BTN3 to
enter the values through the switches.
Negative numbers will be indicated by turning on
the most significant LED by pushing 80h in the
LD-reg Overflow is indicated by lighting up
all the LEDs
19
?
20
MERRY CHRISTMAS AND A HAPPY NEW YEAR TO ALL
Write a Comment
User Comments (0)
About PowerShow.com