mirror of
https://github.com/cc65/cc65.git
synced 2024-12-23 04:30:10 +00:00
Added a test program to test the 16 bit shift ops.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5782 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
49e5d19950
commit
18f22506ba
136
testcode/lib/shift-test.c
Normal file
136
testcode/lib/shift-test.c
Normal file
@ -0,0 +1,136 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
static unsigned UnsignedShiftLeft1 (unsigned Val)
|
||||
/* Shift an unsigned left by 1 */
|
||||
{
|
||||
__AX__ = Val;
|
||||
asm ("stx tmp1");
|
||||
asm ("asl a");
|
||||
asm ("rol tmp1");
|
||||
asm ("ldx tmp1");
|
||||
return __AX__;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static unsigned UnsignedShiftRight1 (unsigned Val)
|
||||
/* Shift an unsigned right by 1 */
|
||||
{
|
||||
__AX__ = Val;
|
||||
asm ("stx tmp1");
|
||||
asm ("lsr tmp1");
|
||||
asm ("ror a");
|
||||
asm ("ldx tmp1");
|
||||
return __AX__;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int SignedShiftRight1 (int Val)
|
||||
/* Shift a signed right by 1 */
|
||||
{
|
||||
__AX__ = Val;
|
||||
asm ("stx tmp1");
|
||||
asm ("cpx #$80");
|
||||
asm ("ror tmp1");
|
||||
asm ("ror a");
|
||||
asm ("ldx tmp1");
|
||||
return __AX__;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void TestUnsignedLeftShift (void)
|
||||
/* Test left shift. This is identical for signed and unsigned ints */
|
||||
{
|
||||
unsigned L, R, V;
|
||||
printf ("Testing unsigned left shift:\n");
|
||||
L = 0;
|
||||
do {
|
||||
V = L;
|
||||
for (R = 0; R < 16; ++R) {
|
||||
/* Check it */
|
||||
if ((L << R) != V) {
|
||||
fprintf (stderr,
|
||||
"Failed: %u << %u != %u (%u)\n",
|
||||
L, R, V, L << R);
|
||||
exit (1);
|
||||
}
|
||||
V = UnsignedShiftLeft1 (V);
|
||||
}
|
||||
if ((L & 0xFF) == 0) {
|
||||
printf ("%04X ", L);
|
||||
}
|
||||
} while (++L != 0);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void TestUnsignedRightShift (void)
|
||||
/* Test unsigned right shift. */
|
||||
{
|
||||
unsigned L, R, V;
|
||||
printf ("Testing unsigned right shift:\n");
|
||||
L = 0;
|
||||
do {
|
||||
V = L;
|
||||
for (R = 0; R < 16; ++R) {
|
||||
/* Check it */
|
||||
if ((L >> R) != V) {
|
||||
fprintf (stderr,
|
||||
"Failed: %u >> %u != %u (%u)\n",
|
||||
L, R, V, L >> R);
|
||||
exit (1);
|
||||
}
|
||||
V = UnsignedShiftRight1 (V);
|
||||
}
|
||||
if ((L & 0xFF) == 0) {
|
||||
printf ("%04X ", L);
|
||||
}
|
||||
} while (++L != 0);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void TestSignedRightShift (void)
|
||||
/* Test signed right shift. */
|
||||
{
|
||||
int L, R, V;
|
||||
printf ("Testing signed right shift:\n");
|
||||
L = 0;
|
||||
do {
|
||||
V = L;
|
||||
for (R = 0; R < 16; ++R) {
|
||||
/* Check it */
|
||||
if ((L >> R) != V) {
|
||||
fprintf (stderr,
|
||||
"Failed: %d >> %d != %d (%d)\n",
|
||||
L, R, V, L >> R);
|
||||
exit (1);
|
||||
}
|
||||
V = SignedShiftRight1 (V);
|
||||
}
|
||||
if ((L & 0xFF) == 0) {
|
||||
printf ("%04X ", L);
|
||||
}
|
||||
} while (++L != 0);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
TestUnsignedLeftShift ();
|
||||
TestUnsignedRightShift ();
|
||||
TestSignedRightShift ();
|
||||
printf ("\nOk!\n");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user