summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mixlib/mix_types.c17
-rw-r--r--mixlib/testsuite/mix_vm_ins_t.c13
-rw-r--r--samples/Makefile.am4
-rw-r--r--samples/minus_zero.mixal8
4 files changed, 27 insertions, 15 deletions
diff --git a/mixlib/mix_types.c b/mixlib/mix_types.c
index 4dac3ba..a29f381 100644
--- a/mixlib/mix_types.c
+++ b/mixlib/mix_types.c
@@ -1,7 +1,7 @@
/* -*-c-*- ------------------ mix_types.c :
* Implementation file for mix_types.h declarations.
* ------------------------------------------------------------------
- * Copyright (C) 2000, 2001, 2002, 2004, 2006, 2007 Free Software Foundation, Inc.
+ * Copyright (C) 2000, 2001, 2002, 2004, 2006, 2007, 2019 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -202,18 +202,17 @@ mix_word_add (mix_word_t x, mix_word_t y)
/* for instance MIX_WORD_MAX + 1 = - MIX_WORD_MAX */
result = MIX_WORD_MAX_SIM - result;
result |= mix_word_sign (mix_word_negative (x));
- } else if ( result != 0 )
+ } else {
result |= mix_word_sign (x);
- /* keep positive sign for 0 so that w - w == -w + w */
+ }
}
else
{
result = mix_word_magnitude (x) - mix_word_magnitude (y);
if (result < 0)
result = -result|mix_word_sign (y);
- else if (result > 0)
+ else
result = result|mix_word_sign (x);
- /* keep positive sign for 0 so that w - w == -w + w */
}
g_assert ( result >= 0 );
@@ -266,10 +265,8 @@ mix_word_add_and_carry (mix_word_t x, mix_word_t y,
gint32 dif = mix_word_magnitude (x) - mix_word_magnitude (y);
if ( dif < 0)
*l = (-dif)|mix_word_sign (y);
- else if ( dif > 0)
+ else
*l = dif|mix_word_sign (x);
- else /* keep positive sign for 0 so that w - w == -w + w */
- *l = MIX_WORD_ZERO;
}
}
@@ -595,7 +592,3 @@ mix_short_print_to_buffer (mix_short_t s, gchar *buf)
mix_byte_new (s>>6), mix_byte_new (s));
/* g_print ("(%04d)", mix_short_magnitude (s));*/
}
-
-
-
-
diff --git a/mixlib/testsuite/mix_vm_ins_t.c b/mixlib/testsuite/mix_vm_ins_t.c
index 1d368a7..239b737 100644
--- a/mixlib/testsuite/mix_vm_ins_t.c
+++ b/mixlib/testsuite/mix_vm_ins_t.c
@@ -135,6 +135,18 @@ test_arithmetics_(mix_vm_t *vm, mix_dump_context_t *dc)
test.rA_a = mix_word_new_b(20,54,6,3,8);
run_test_(&test, vm, dc);
+ mix_vm_set_rA(vm, mix_word_new_bn(0,0,0,0,1));
+ mix_vm_set_addr_contents(vm, 1000, mix_word_new_b(0,0,0,0,1));
+ fill_test_desc_(&test,vm,&ins);
+ test.rA_a = MIX_WORD_MINUS_ZERO;
+ run_test_(&test, vm, dc);
+
+ mix_vm_set_rA(vm, mix_word_new_b(0,0,0,0,1));
+ mix_vm_set_addr_contents(vm, 1000, mix_word_new_bn(0,0,0,0,1));
+ fill_test_desc_(&test,vm,&ins);
+ test.rA_a = MIX_WORD_ZERO;
+ run_test_(&test, vm, dc);
+
mix_ins_fill_from_id(ins,mix_SUB);
mix_vm_set_rA(vm,mix_word_new_bn(19,18,0,0,9));
mix_vm_set_addr_contents(vm,1000,mix_word_new_bn(31,16,2,22,0));
@@ -519,4 +531,3 @@ main(int argc, const char **argv)
return EXIT_SUCCESS;
}
-
diff --git a/samples/Makefile.am b/samples/Makefile.am
index 357b5f3..c1dcfa6 100644
--- a/samples/Makefile.am
+++ b/samples/Makefile.am
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
-# Copyright (C) 2000, 2001, 2004, 2006, 2013 Free Software Foundation, Inc.
+# Copyright (C) 2000, 2001, 2004, 2006, 2013, 2019 Free Software Foundation, Inc.
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
@@ -14,4 +14,4 @@ SUBDIRS = tests
EXTRA_DIST = primes.result hello.mixal primes.mixal echo.mixal \
permutations.mixal permutations.cardrd isains.mixal \
- elevator.mixal mystery.mixal
+ elevator.mixal mystery.mixal minus_zero.mixal
diff --git a/samples/minus_zero.mixal b/samples/minus_zero.mixal
new file mode 100644
index 0000000..9adb914
--- /dev/null
+++ b/samples/minus_zero.mixal
@@ -0,0 +1,8 @@
+ ORIG 3000
+START ENTA 1
+ STA 1000
+ LDA 0
+ DECA 1
+ ADD 1000
+ HLT
+ END 3000