Starting ALU
This commit is contained in:
parent
53b89bcf65
commit
25837b08f9
22
src/modal.c
22
src/modal.c
|
@ -31,10 +31,30 @@ walk(char *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
|
||||
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;
|
||||
while(s < cap) {
|
||||
c = *s++;
|
||||
|
|
Loading…
Reference in New Issue