shithub: scc

Download patch

ref: c4f7f014ec27b9c5495b088642c6a6dfb8161340
parent: dfa2d2ccc8a950ba4696ac3b1a16be6089e8ac90
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Sep 21 07:24:48 EDT 2019

[as] Implement toobig()

This function checks if an immediate is valid based in a type.

--- a/src/cmd/as/as.h
+++ b/src/cmd/as/as.h
@@ -32,6 +32,8 @@
 	ASTR,
 	AREG,
 	ANUMBER,
+	AIMM3,
+	AIMM5,
 	AIMM8,
 	AIMM16,
 	AIMM32,
--- a/src/cmd/as/symbol.c
+++ b/src/cmd/as/symbol.c
@@ -1,6 +1,7 @@
 #include <ctype.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include <scc/scc.h>
@@ -117,8 +118,24 @@
 int
 toobig(Node *np, int type)
 {
-	/* TODO */
-	return 0;
+	unsigned long long val = np->sym->value;
+
+	switch (type) {
+	case AIMM3:
+		return val > 7;
+	case AIMM5:
+		return val > 0x1F;
+	case AIMM8:
+		return val > 0xFF;
+	case AIMM16:
+		return val > 0xFFFF;
+	case AIMM32:
+		return val > 0xFFFFFFFF;
+	case AIMM64:
+		return 1;
+	default:
+		abort();
+	}
 }
 
 static void
--- a/src/cmd/as/target/x80/ins.c
+++ b/src/cmd/as/target/x80/ins.c
@@ -164,9 +164,10 @@
 		index_address:
 			if (np->addr != AINDEX)
 				return 0;
-			if (np->left->left->sym->value != arg)
+			np = np->left->left;
+			if (np->sym->value != arg)
 				return 0;
-			if (toobig(np, arg))
+			if (toobig(np, AIMM8))
 				error("overflow in index");
 			break;
 		case ARST:
@@ -176,6 +177,9 @@
 				return 0;
 			break;
 		case AZERO:
+			if (np->addr != AIMM)
+				return 0;
+			break;
 		case AIMM3:
 		case AIMM8:
 		case AIMM16:
--- a/src/cmd/as/target/x80/proc.h
+++ b/src/cmd/as/target/x80/proc.h
@@ -57,7 +57,6 @@
 	AINDER_IX,    /* (IX) */
 	AINDER_IY,    /* (IY) */
 
-	AIMM3,         /* 3 bit immediate */
 	AZERO,         /* a literal 0 */
 	ARST,          /* 0h, 08h, 10h, 18h, 20h, 28h, 30h, 38h */
 };