From ad1fddf495e80b3bdf4353927b6704f188be4578 Mon Sep 17 00:00:00 2001 From: Christian Klein Date: Wed, 4 May 2022 16:19:45 +0200 Subject: [PATCH] Add bitwise operations to ALU --- out/index.html | 32 ++++++++++++++++++++++++++++++++ src/PC/Types.elm | 4 ++++ src/PC/UActions.elm | 21 +++++++++++++++++++++ src/PC/View.elm | 7 +++++++ 4 files changed, 64 insertions(+) diff --git a/out/index.html b/out/index.html index f508751..0bc9dd6 100644 --- a/out/index.html +++ b/out/index.html @@ -211,6 +211,22 @@ Instr Argument Acc / DataBus Dividiere den Akkumulator durch den Datenbus + + Acc AND DataBus + Führe bitweise UND auf Akkumulator mit Datenbus aus + + + Acc OR DataBus + Führe bitweise ODER auf Akkumulator mit Datenbus aus + + + Acc XOR DataBus + Führe bitweise XOR auf Akkumulator mit Datenbus aus + + + Acc NOT DataBus + Führe bitweise NOT auf Akkumulator mit Datenbus aus + InstReg -> µCounter Nehme das Argument des Befehls im Instruktionsregister, füge am Ende eine 0 an und Lade ihn in den µCounter @@ -409,6 +425,22 @@ Instr Argument Acc / DataBus Divide the accumulator by the value of the databus + + Acc AND DataBus + Do a bitwise AND to accumulator with the value of the databus + + + Acc OR DataBus + Do a bitwise OR to accumulator with the value of the databus + + + Acc XOR DataBus + Do a bitwise XOR to accumulator with the value of the databus + + + Acc NOT DataBus + Do a bitwise NOT to accumulator with the value of the databus + InstReg -> µCounter Take the instruction from instruction register, add a 0 at the tail and write it to µCounter diff --git a/src/PC/Types.elm b/src/PC/Types.elm index 7cf4500..73a0e26 100644 --- a/src/PC/Types.elm +++ b/src/PC/Types.elm @@ -37,6 +37,10 @@ type UAction | UA_ALU_AccumulatorSubtractByDataBus | UA_ALU_AccumulatorMultiplyByDataBus | UA_ALU_AccumulatorDivideByDataBus + | UA_ALU_AccumulatorANDDataBus + | UA_ALU_AccumulatorORDataBus + | UA_ALU_AccumulatorXORDataBus + | UA_ALU_AccumulatorNOT | UA_CU_InstructionReg2AddressBus | UA_CU_InstructionReg2DataBus | UA_CU_InstructionReg2ProgrammCounter diff --git a/src/PC/UActions.elm b/src/PC/UActions.elm index 3ed35f7..039732e 100644 --- a/src/PC/UActions.elm +++ b/src/PC/UActions.elm @@ -5,6 +5,7 @@ module PC.UActions exposing ( uCodes import Array exposing (Array) import Tuple +import Bitwise import PC.Types exposing (..) import PC.Helpers exposing (..) @@ -21,6 +22,10 @@ uCodes = , UCode UA_ALU_AccumulatorSubtractByDataBus "accSub" actAccumulatorSub "Acc - DataBus" , UCode UA_ALU_AccumulatorMultiplyByDataBus "accMul" actAccumulatorMultiply "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_InstructionReg2DataBus "ir2db" actInstructionReg2DataBus "InstReg -> DataBus" , UCode UA_CU_InstructionReg2ProgrammCounter "ir2pc" actInstructionReg2ProgrammCounter "InstReg -> ProgCount" @@ -158,6 +163,22 @@ actAccumulatorDivide : PC -> PC actAccumulatorDivide pc = { 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 diff --git a/src/PC/View.elm b/src/PC/View.elm index ebf92d6..82a0105 100644 --- a/src/PC/View.elm +++ b/src/PC/View.elm @@ -292,6 +292,13 @@ viewAlu model = , button [ onClick <| PM_ManualStep UA_ALU_AccumulatorMultiplyByDataBus ] [ 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" ] [ drawArrow Up UA_DataBus2Accumulator "DB -> ALU"