From f0cea166e4a15c5b53a8d20c362feab33e73338e Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sat, 28 May 2022 17:47:51 -0700 Subject: [PATCH] Fixing bug in RSHIFT. --- common/base_tests.fs | 9 +++++++++ common/opcodes.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/common/base_tests.fs b/common/base_tests.fs index c8a3f09..c414990 100644 --- a/common/base_tests.fs +++ b/common/base_tests.fs @@ -129,3 +129,12 @@ e: test-?dup 0 ?dup 0 =assert depth 0 =assert ;e + +e: test-lshift + $1234 4 lshift $12340 =assert +;e + +e: test-rshift + $1234 4 rshift $123 =assert + -1 cell 8 * 1- rshift 1 =assert +;e diff --git a/common/opcodes.h b/common/opcodes.h index 011ebfc..bfa55ca 100644 --- a/common/opcodes.h +++ b/common/opcodes.h @@ -82,7 +82,7 @@ typedef struct { tos = (ucell_t) w / (ucell_t) tos) \ X("*/MOD", SSMOD, SSMOD_FUNC) \ Y(LSHIFT, tos = (*sp-- << tos)) \ - Y(RSHIFT, tos = (*sp-- >> tos)) \ + Y(RSHIFT, tos = (((ucell_t) *sp--) >> tos)) \ Y(AND, tos &= *sp--) \ Y(OR, tos |= *sp--) \ Y(XOR, tos ^= *sp--) \