commit 33736af6fe6377f78d180614bbd26b86ac36051b
parent e93508dc7b827063f4c2fce7308b39eba0b8516d
Author: Paul Longtine <paul@nanner.co>
Date: Wed, 27 Jan 2021 02:37:20 -0500
Add base 2 and base 16 integer representations for intermediate values
Diffstat:
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/ExamplePrograms/README.md b/ExamplePrograms/README.md
@@ -31,6 +31,12 @@ Please refer to other examples as reference.
* `<label>` specifies the argument as a label
+ * `<0-15>` `<0-255>` specifies an integer value
+ * The following formats are accepted:
+ * Base 10
+ * Base 16: Prefixed with `0x`
+ * Base 2: Prefixed with `0b`
+
## 0 Argument Instructions
Do nothing and reset the set operation to ADD
diff --git a/tisc.c b/tisc.c
@@ -228,13 +228,33 @@ int assemble_3arg(
return 1;
}
+int stringToInteger(char* str)
+{
+ int return_value = -1;
+
+ if (strncmp("0x", str, 2) == 0)
+ {
+ return_value = (int)strtol(str+2, NULL, 16);
+ }
+ else if (strncmp("0b", str, 2) == 0)
+ {
+ return_value = (int)strtol(str+2, NULL, 2);
+ }
+ else
+ {
+ return_value = atoi(str);
+ }
+
+ return return_value;
+}
+
int assemble_immediate(
InstructionDefinition_t *definition,
char* arg[3], uint8_t* write_buffer)
{
int return_value = 0;
- int immediate_value = atoi(arg[0]);
+ int immediate_value = stringToInteger(arg[0]);
if (immediate_value < 0x0F && immediate_value >= 0)
{
@@ -252,7 +272,7 @@ int assemble_li(
{
int return_value = 0;
- int immediate_value = atoi(arg[0]);
+ int immediate_value = stringToInteger(arg[0]);
if (immediate_value <= 0xFF && immediate_value >= 0)
{