Use read_opcode function

This commit is contained in:
2024-12-17 17:09:19 +08:00
parent e02ee993c6
commit de2fd03c3c
3 changed files with 55 additions and 166 deletions

View File

@ -23,39 +23,7 @@ while [[ $POINTER -lt $INPUT_LEN ]]
do
OPCODE=${INPUT[$POINTER]}
OPERAND=${INPUT[$POINTER+1]}
if [[ $OPCODE -eq 0 ]]
then
adv "$OPERAND"
(( POINTER+=2 ))
elif [[ $OPCODE -eq 1 ]]
then
bxl "$OPERAND"
(( POINTER+=2 ))
elif [[ $OPCODE -eq 2 ]]
then
bst "$OPERAND"
(( POINTER+=2 ))
elif [[ $OPCODE -eq 3 ]]
then
# jnz itself moves the pointer
jnz "$OPERAND"
elif [[ $OPCODE -eq 4 ]]
then
bxc "$OPERAND"
(( POINTER+=2 ))
elif [[ $OPCODE -eq 5 ]]
then
out "$OPERAND"
(( POINTER+=2 ))
elif [[ $OPCODE -eq 6 ]]
then
bdv "$OPERAND"
(( POINTER+=2 ))
elif [[ $OPCODE -eq 7 ]]
then
cdv "$OPERAND"
(( POINTER+=2 ))
fi
read_opcode "$OPCODE" "$OPERAND"
printf "Registers A : %s B: %s C : %s\n" "$REG_A" "$REG_B" "$REG_C" >&2
printf "Pointer : %s\n" "$POINTER" >&2
(( ITER-- ))