# This source file is licensed under the BSD Zero-Clause License. # You are free to use, modify, and distribute this file without restriction. # See LICENSE-BSD-0.txt for details. ######################## ## Set Up Environment ## ######################## # Compile ALU design vlog alu.sv # Start graphical simulation vsim -gui work.alu # Restart simulation without prompt or messages restart -force -nolog # View waveform diagram in its own window view wave ################ ## Add Inputs ## ################ add wave -divider Inputs add wave -group Inputs -radix hexadecimal sim:/alu/x add wave -group Inputs -radix hexadecimal sim:/alu/y add wave -group Inputs -group Control sim:/alu/zx add wave -group Inputs -group Control sim:/alu/nx add wave -group Inputs -group Control sim:/alu/zy add wave -group Inputs -group Control sim:/alu/ny add wave -group Inputs -group Control sim:/alu/fn add wave -group Inputs -group Control sim:/alu/no ############################ ## Add Intermediate Logic ## ############################ add wave -divider Intermediate add wave -group Intermediate -radix hexadecimal sim:/alu/zeroed_x add wave -group Intermediate -radix hexadecimal sim:/alu/zeroed_y add wave -group Intermediate -radix hexadecimal sim:/alu/final_x add wave -group Intermediate -radix hexadecimal sim:/alu/final_y add wave -group Intermediate -radix hexadecimal sim:/alu/output_and add wave -group Intermediate -radix hexadecimal sim:/alu/output_add add wave -group Intermediate sim:/alu/add_overflow add wave -group Intermediate -radix hexadecimal sim:/alu/output_raw ################# ## Add Outputs ## ################# add wave -divider Outputs add wave -group Outputs -radix hexadecimal sim:/alu/out add wave -group Outputs -group Flags sim:/alu/zr add wave -group Outputs -group Flags sim:/alu/ng add wave -group Outputs -group Flags sim:/alu/ov ##################### ## Add Two Numbers ## ##################### # Adds 0x20 + 0x47, expected output should be 0x67 force x 16'h0020 force y 16'h0047 force zx 0 force nx 0 force zy 0 force ny 0 force fn 1 force no 0 run 10 ###################### ## Extract Low Byte ## ###################### # Get low byte of x by ANDing with 0x00ff # Computes 0x9D95 & 0x00ff. Sets highest 8 bits to 0 # 1001 1101 1001 0101 (0x9D95) # & 0000 0000 1111 1111 (0x00ff) # ---------------------- # 0000 0000 1001 0101 (0x0095) force x 16'h9D95 force y 16'h00FF force zx 0 force nx 0 force zy 0 force ny 0 force fn 0 force no 0 run 10 ################ ## Bitwise OR ## ################ # x | y = ~(~x & ~y) # Computes 0x5555 | 0x003f. Sets lowest 6 bits high. # 0101 0101 0101 0101 (0x5555) # | 0000 0000 0011 1111 (0x003f) # ---------------------- # 0101 0101 0111 1111 (0x557f) force x 16'h5555 force y 16'h003f force zx 0 force nx 1 force zy 0 force ny 1 force fn 0 force no 1 run 10 ######################### ## Compare Two Numbers ## ######################### # Compare by subtracting then checking flags # Subtraction x - y = ~(~x + y) force zx 0 force nx 1 force zy 0 force ny 0 force fn 1 force no 1 # x = y; Positive force x 16'h5A5A force y 16'h5A5A run 10 # x < y; Positive force y 16'h6A6A run 10 # x > y; Positive force y 16'h005A run 10 # x = y; Negative force x 16'hA5A5 force y 16'hA5A5 run 10 # x < y; Negative force y 16'hA6A6 run 10 # x > y; Negative force y 16'h00A5 run 10