Starting ALU

This commit is contained in:
Devine Lu Linvega 2024-04-28 19:45:46 -07:00
parent 53b89bcf65
commit 25837b08f9
1 changed files with 21 additions and 1 deletions

View File

@ -31,10 +31,30 @@ walk(char *s)
return s; return s;
} }
static int
sint(char *s)
{
int acc = 0;
char c;
while((c = *s++) && c > 0x20) acc *= 10, acc += c - '0';
return acc;
}
static void static void
device_write(char *s) device_write(char *s)
{ {
char c, *cap = walk(s); int acc = 0;
char c = *s, *cap = walk(s), *reg = regs['0'];
if(reg) {
switch(c) {
case '+':
for(acc = sint(reg++); *reg; reg++) acc = acc + sint(reg);
break;
}
dst_ += snprintf(dst_, 0x10, "%d\n", acc);
return;
}
if(*s == '(') s++, --cap; if(*s == '(') s++, --cap;
while(s < cap) { while(s < cap) {
c = *s++; c = *s++;