register ripout

This commit is contained in:
able 2024-03-07 10:39:55 -06:00
parent 8a7639d6ba
commit 8597d97566
2 changed files with 31 additions and 31 deletions

View file

@ -29,6 +29,7 @@ SOFTWARE.
#include "error.h"
#include "instructions.c"
#include "hash.c"
#include "register.c"
void hd(char *data, size_t len)
{
@ -381,37 +382,6 @@ size_t label_lookup(LabelVec *labels, char *name, size_t len)
return INVALID;
}
int parse_register(char *name, size_t len)
{
if (name[0] != 'r')
{
return 256; // Register name should start with 'r'
}
if (len > 4)
{
return 256; // Register name too long
}
uint16_t rv = 0;
if (len > 2 && name[1] == '0')
{
return 256; // Extra zero suffix
}
for (size_t ii = 1; ii < len; ii += 1)
{
char chr = name[ii];
if (!(chr >= '0' && chr <= '9'))
{
return 256; // Register name must only contain numbers
}
rv = rv * 10 + (chr - '0');
}
if (rv > 255)
{
return 256; // Register number too large
}
return (int)rv;
}
// safety: assumes the buffer has enough place for specified integer size
AsmError push_int_le(char *buf, uint64_t val, size_t size, uint8_t sign)
{

30
src/register.c Normal file
View file

@ -0,0 +1,30 @@
int parse_register(char *name, size_t len)
{
if (name[0] != 'r')
{
return 256; // Register name should start with 'r'
}
if (len > 4)
{
return 256; // Register name too long
}
uint16_t rv = 0;
if (len > 2 && name[1] == '0')
{
return 256; // Extra zero suffix
}
for (size_t ii = 1; ii < len; ii += 1)
{
char chr = name[ii];
if (!(chr >= '0' && chr <= '9'))
{
return 256; // Register name must only contain numbers
}
rv = rv * 10 + (chr - '0');
}
if (rv > 255)
{
return 256; // Register number too large
}
return (int)rv;
}