Add bitwise operations to ALU

This commit is contained in:
Christian 2022-05-04 16:19:45 +02:00
parent 90dae6963b
commit ad1fddf495
4 changed files with 64 additions and 0 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

@ -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"