Merge pull request 'Added Bitwise Operations' (#2) from dev into master

Reviewed-on: #2
This commit is contained in:
Christian 2022-05-04 16:22:44 +02:00
commit e3c4355d58
5 changed files with 79 additions and 6 deletions

View File

@ -211,6 +211,22 @@ Instr Argument
<td><code>Acc / DataBus</code></td> <td><code>Acc / DataBus</code></td>
<td>Dividiere den Akkumulator durch den Datenbus</td> <td>Dividiere den Akkumulator durch den Datenbus</td>
</tr> </tr>
<tr>
<td><code>Acc AND DataBus</code></td>
<td>Führe bitweise UND auf Akkumulator mit Datenbus aus</td>
</tr>
<tr>
<td><code>Acc OR DataBus</code></td>
<td>Führe bitweise ODER auf Akkumulator mit Datenbus aus</td>
</tr>
<tr>
<td><code>Acc XOR DataBus</code></td>
<td>Führe bitweise XOR auf Akkumulator mit Datenbus aus</td>
</tr>
<tr>
<td><code>Acc NOT DataBus</code></td>
<td>Führe bitweise NOT auf Akkumulator mit Datenbus aus</td>
</tr>
<tr> <tr>
<td><code>InstReg -> µCounter</code></td> <td><code>InstReg -> µCounter</code></td>
<td>Nehme das Argument des Befehls im Instruktionsregister, füge am Ende eine 0 an und Lade ihn in den µCounter</td> <td>Nehme das Argument des Befehls im Instruktionsregister, füge am Ende eine 0 an und Lade ihn in den µCounter</td>
@ -409,6 +425,22 @@ Instr Argument
<td><code>Acc / DataBus</code></td> <td><code>Acc / DataBus</code></td>
<td>Divide the accumulator by the value of the databus</td> <td>Divide the accumulator by the value of the databus</td>
</tr> </tr>
<tr>
<td><code>Acc AND DataBus</code></td>
<td>Do a bitwise AND to accumulator with the value of the databus</td>
</tr>
<tr>
<td><code>Acc OR DataBus</code></td>
<td>Do a bitwise OR to accumulator with the value of the databus</td>
</tr>
<tr>
<td><code>Acc XOR DataBus</code></td>
<td>Do a bitwise XOR to accumulator with the value of the databus</td>
</tr>
<tr>
<td><code>Acc NOT DataBus</code></td>
<td>Do a bitwise NOT to accumulator with the value of the databus</td>
</tr>
<tr> <tr>
<td><code>InstReg -> µCounter</code></td> <td><code>InstReg -> µCounter</code></td>
<td>Take the instruction from instruction register, add a 0 at the tail and write it to µCounter</td> <td>Take the instruction from instruction register, add a 0 at the tail and write it to µCounter</td>

View File

@ -9,12 +9,21 @@ import Http exposing (..)
-- Please note that only 0 are added. The number will not be shortend! -- Please note that only 0 are added. The number will not be shortend!
addLeadingZero : Int -> Int -> String addLeadingZero : Int -> Int -> String
addLeadingZero number length = addLeadingZero number length =
let if number >= 0 then
num_str = String.fromInt number let
in num_str = String.fromInt number
(String.fromList <| List.repeat (length - String.length num_str) '0' in
) (String.fromList <| List.repeat (length - String.length num_str) '0'
++ num_str )
++ num_str
else
let
num_str = String.fromInt <| 0-number
in
"-" ++
(String.fromList <| List.repeat (length - String.length num_str) '0'
)
++ num_str
-- Get the value at a given position in a List. -- Get the value at a given position in a List.

View File

@ -37,6 +37,10 @@ type UAction
| UA_ALU_AccumulatorSubtractByDataBus | UA_ALU_AccumulatorSubtractByDataBus
| UA_ALU_AccumulatorMultiplyByDataBus | UA_ALU_AccumulatorMultiplyByDataBus
| UA_ALU_AccumulatorDivideByDataBus | UA_ALU_AccumulatorDivideByDataBus
| UA_ALU_AccumulatorANDDataBus
| UA_ALU_AccumulatorORDataBus
| UA_ALU_AccumulatorXORDataBus
| UA_ALU_AccumulatorNOT
| UA_CU_InstructionReg2AddressBus | UA_CU_InstructionReg2AddressBus
| UA_CU_InstructionReg2DataBus | UA_CU_InstructionReg2DataBus
| UA_CU_InstructionReg2ProgrammCounter | UA_CU_InstructionReg2ProgrammCounter

View File

@ -5,6 +5,7 @@ module PC.UActions exposing ( uCodes
import Array exposing (Array) import Array exposing (Array)
import Tuple import Tuple
import Bitwise
import PC.Types exposing (..) import PC.Types exposing (..)
import PC.Helpers exposing (..) import PC.Helpers exposing (..)
@ -21,6 +22,10 @@ uCodes =
, UCode UA_ALU_AccumulatorSubtractByDataBus "accSub" actAccumulatorSub "Acc - DataBus" , UCode UA_ALU_AccumulatorSubtractByDataBus "accSub" actAccumulatorSub "Acc - DataBus"
, UCode UA_ALU_AccumulatorMultiplyByDataBus "accMul" actAccumulatorMultiply "Acc * DataBus" , UCode UA_ALU_AccumulatorMultiplyByDataBus "accMul" actAccumulatorMultiply "Acc * DataBus"
, UCode UA_ALU_AccumulatorDivideByDataBus "accDiv" actAccumulatorDivide "Acc / DataBus" , UCode UA_ALU_AccumulatorDivideByDataBus "accDiv" actAccumulatorDivide "Acc / DataBus"
, UCode UA_ALU_AccumulatorANDDataBus "accAND" actAccumulatorAND "Acc AND DataBus"
, UCode UA_ALU_AccumulatorORDataBus "accOR" actAccumulatorOR "Acc OR DataBus"
, UCode UA_ALU_AccumulatorXORDataBus "accXOR" actAccumulatorXOR "Acc XOR DataBus"
, UCode UA_ALU_AccumulatorNOT "accNOT" actAccumulatorNOT "Acc NOT"
, UCode UA_CU_InstructionReg2AddressBus "ir2ab" actInstructionReg2AddressBus "InstReg -> AddrBus" , UCode UA_CU_InstructionReg2AddressBus "ir2ab" actInstructionReg2AddressBus "InstReg -> AddrBus"
, UCode UA_CU_InstructionReg2DataBus "ir2db" actInstructionReg2DataBus "InstReg -> DataBus" , UCode UA_CU_InstructionReg2DataBus "ir2db" actInstructionReg2DataBus "InstReg -> DataBus"
, UCode UA_CU_InstructionReg2ProgrammCounter "ir2pc" actInstructionReg2ProgrammCounter "InstReg -> ProgCount" , UCode UA_CU_InstructionReg2ProgrammCounter "ir2pc" actInstructionReg2ProgrammCounter "InstReg -> ProgCount"
@ -158,6 +163,22 @@ actAccumulatorDivide : PC -> PC
actAccumulatorDivide pc = actAccumulatorDivide pc =
{ pc | accumulator = pc.accumulator // pc.dataBus } { pc | accumulator = pc.accumulator // pc.dataBus }
actAccumulatorAND : PC -> PC
actAccumulatorAND pc =
{ pc | accumulator = Bitwise.and pc.accumulator pc.dataBus }
actAccumulatorOR : PC -> PC
actAccumulatorOR pc =
{ pc | accumulator = Bitwise.or pc.accumulator pc.dataBus }
actAccumulatorXOR : PC -> PC
actAccumulatorXOR pc =
{ pc | accumulator = Bitwise.xor pc.accumulator pc.dataBus }
actAccumulatorNOT : PC -> PC
actAccumulatorNOT pc =
{ pc | accumulator = Bitwise.complement pc.accumulator }
actDataBus2Ram : PC -> PC actDataBus2Ram : PC -> PC

View File

@ -292,6 +292,13 @@ viewAlu model =
, button [ onClick <| PM_ManualStep UA_ALU_AccumulatorMultiplyByDataBus ] [ text "*" ] , button [ onClick <| PM_ManualStep UA_ALU_AccumulatorMultiplyByDataBus ] [ text "*" ]
, button [ onClick <| PM_ManualStep UA_ALU_AccumulatorDivideByDataBus ] [ text "/" ] , button [ onClick <| PM_ManualStep UA_ALU_AccumulatorDivideByDataBus ] [ text "/" ]
] ]
, Html.span [] [ text "Bitwise operations"]
, div [ class "button-group-alu__4-elements" ]
[ button [ onClick <| PM_ManualStep UA_ALU_AccumulatorANDDataBus ] [ text "AND" ]
, button [ onClick <| PM_ManualStep UA_ALU_AccumulatorORDataBus ] [ text "OR" ]
, button [ onClick <| PM_ManualStep UA_ALU_AccumulatorXORDataBus ] [ text "XOR" ]
, button [ onClick <| PM_ManualStep UA_ALU_AccumulatorNOT ] [ text "NOT" ]
]
] ]
, div [ class "arrow-line", class "bottom" ] , div [ class "arrow-line", class "bottom" ]
[ drawArrow Up UA_DataBus2Accumulator "DB -> ALU" [ drawArrow Up UA_DataBus2Accumulator "DB -> ALU"