Skip to content

Commit

Permalink
gcc: add support for the lt and gt comparison operators
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Kokosiński <filip.kokosinski@gmail.com>
  • Loading branch information
fkokosinski committed Jun 13, 2024
1 parent d9108b1 commit e1ed6df
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
6 changes: 3 additions & 3 deletions c-print-array/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ void _start(void)
putc(x[2]);

/* check with global iterator */
for (i = 0; i != 3; i++)
for (i = 0; i < 3; i++)
putc(x[i]);

/* check with local iterator w/o func call */
for (int j = 0; j != 3; j++) {
for (int j = 0; j < 3; j++) {
asm ("lio %0" : : "r"(x[j]));
asm ("tyo");
}

/* check with local iterator w/ func call */
for (int j = 0; j != 3; j++)
for (int j = 0; j < 3; j++)
putc(x[j]);

asm ("hlt");
Expand Down
1 change: 1 addition & 0 deletions c-test-comparison/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../common/common.mk
54 changes: 54 additions & 0 deletions c-test-comparison/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
static void putc(int);

void _start(void)
{
/* TODO: handle sp/fp init better -- separate crt0.S? */
asm ("law 03000");
asm ("dac 209");
asm ("law 04000");
asm ("dac 208");

int x = 30;
int y = 30;

/* test if `==` works */
if (x == y)
putc(061); // a
if (x != y)
putc(062); // b

/* test if `!=` works */
x = 21;
y = 37;
if (x != y)
putc(063); // c
if (x == y)
putc(064); // d

/* test if `<` works */
if (x < y)
putc(065); // e
y = 21;
if (x < y)
putc(066); // f

/* test if `>` works */
x = 41;
y = 37;
if (x > y)
putc(067); // g
x = 37;
if (x > y)
putc(070); // h
x = 21;
if (x > y)
putc(071); // i

asm ("hlt");
__builtin_unreachable();
}

static void putc(int c) {
asm ("lio %0" : : "r"(c));
asm ("tyo");
}
2 changes: 1 addition & 1 deletion pdp1-binutils
2 changes: 1 addition & 1 deletion pdp1-gcc
1 change: 1 addition & 0 deletions tests/test.exp
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ run_test "c-print-x" "xx"
run_test "c-print-struct" "xyz"
run_test "c-print-array" "xyzxyzxyzxyz"
run_test "c-print-for-loop" "xxxxyxxx"
run_test "c-test-comparison" "aceg"

0 comments on commit e1ed6df

Please sign in to comment.