nctref/tests/bf.nct

79 lines
1.3 KiB
Plaintext
Raw Normal View History

2023-08-27 19:48:06 +03:00
@section(".data");
local u8[16384] data:;
local u8[16384] code:;
local u32[64] stck:;
@section(".text");
extern u32(u32, u8*, u32) write;
extern u32(u32, u8*, u32) read;
read(0, &code, 16384);
u32 codePtr = 0;
u32 dataPtr = 0;
u32 stckPtr = 16rFFFFFFFF;
loop {
if(code[codePtr] == 62) {
dataPtr = dataPtr + 1;
}
if(code[codePtr] == 60) {
dataPtr = dataPtr - 1;
}
if(code[codePtr] == 43) {
data[dataPtr] = data[dataPtr] + 1;
}
if(code[codePtr] == 45) {
data[dataPtr] = data[dataPtr] - 1;
}
if(code[codePtr] == 46) {
2024-02-13 21:33:49 +02:00
write(1, &data + dataPtr, 1);
2023-08-27 19:48:06 +03:00
}
if(code[codePtr] == 44) {
2024-02-13 21:33:49 +02:00
read(0, &data + dataPtr, 1);
2023-08-27 19:48:06 +03:00
}
if(code[codePtr] == 91) {
if(data[dataPtr] == 0) {
u32 depth = 0;
loop {
if(code[codePtr] == 91) {
depth = depth + 1;
}
if(code[codePtr] == 93) {
depth = depth - 1;
}
if(depth == 0) {
break;
}
codePtr = codePtr + 1;
}
}
if(data[dataPtr] != 0) {
stckPtr = stckPtr + 1;
stck[stckPtr] = codePtr;
}
codePtr = codePtr + 1;
continue;
}
if(code[codePtr] == 93) {
if(data[dataPtr] == 0) {
stckPtr = stckPtr - 1;
}
if(data[dataPtr] != 0) {
codePtr = stck[stckPtr];
}
}
if(code[codePtr] == 0) {
loop {}
}
codePtr = codePtr + 1;
}
codePtr;
dataPtr;
stckPtr;