home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Hack-Phreak Scene Programs
/
cleanhpvac.zip
/
cleanhpvac
/
FPGAWKII.ZIP
/
COMPLEME.PDS
< prev
next >
Wrap
Text File
|
1994-10-05
|
3KB
|
65 lines
;---------------------------------------------------------
; This is a PLDASM file for a 7-bit 2's-complementer that
; uses the previously-defined 8-bit adder module.
;---------------------------------------------------------
TITLE complementer
CHIP compleme NFX780_84
;---------------------------------------------------------
; To form the 2's-complement of a binary number, you have
; to invert all the bits and add 1. So, use EQUATIONS
; to invert the input bits, and then use the 8-bit adder
; module to add a 1 to the inverted bits.
; This will form the 2's-complement.
;---------------------------------------------------------
PIN [47:51] a[0:4] ;* the number to be 2's-complemented
PIN [77:78] a[6:5]
PIN [34:37] cp[0:3] ;* the 2's-complement of a[0:6]
PIN [39:41] cp[4:6]
PIN cout ;* dump the carry output here
PIN inv[0:6] ;* the inversion of a[0:6] will be
;* stored on these nodes
;---------------------------------------------------------
; Now call the adder module. Note that the compiler must
; be told what FILE the adder module description is stored
; in. Note that no carry input goes to the adder, nor is
; the carry output used. Instead, the carry input is tied
; to ground and the carry output is left floating on a
; NODE variable. Note also that the a input to the adder
; is tied to the inversion of the a input. Note also that
; the least-significant bit of the b adder input is tied
; to VCC (+5V or a logic 1) while the upper 7 bits of the
; b input are grounded (logic 0). With this arrangement,
; a 1 will be added to the inversion of the a input, thus
; giving the desired 2's-complement.
;---------------------------------------------------------
MODULE add8 FILE addmodul ( a[0:6]=inv[0:6], a7=GND,
b0=VCC, b1=GND, b2=GND, b3=GND,
b4=GND, b5=GND, b6=GND, b7=GND,
cin=GND,
sum[0:7]=cp[0:7], cout=cout )
;---------------------------------------------------------
; Here are the logic equations for inverting the a input
;---------------------------------------------------------
EQUATIONS
inv[0:6] = /a[0:6] ;* inverts all 7 inputs with a
;* single statement
;---------------------------------------------------------
; Here is the simulation of the 2's-complementer.
;---------------------------------------------------------
SIMULATION
VECTOR in_a := [a6, a5, a4, a3, a2, a1, a0]
VECTOR comp := [cp6,cp5,cp4,cp3,cp2,cp1,cp0]
TRACE_ON in_a comp
FOR i:=0 TO 127 DO
BEGIN
SETF in_a := i
END