Skip to content

Instantly share code, notes, and snippets.

@lifthrasiir
Created March 1, 2022 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lifthrasiir/0a5987605c0c8537b2e3abfeea31bd27 to your computer and use it in GitHub Desktop.
Save lifthrasiir/0a5987605c0c8537b2e3abfeea31bd27 to your computer and use it in GitHub Desktop.
// really inefficient MicroW8 quine
// 2022-03-01 Kang Seonghoon, public domain
import "env.memory" memory(4);
import "env.printString" fn printString(i32);
export fn upd() {
if 0!64 > 0 {
return;
}
let inline BASE = 0x20000;
let inline PREFIX_LEN = 47;
let inline CODE_LEN = 284;
let inline LEN = PREFIX_LEN + CODE_LEN;
let inline B64_BASE = BASE + LEN;
let inline B64_LEN = LEN / 3 * 4;
let i = 0;
loop copy {
(BASE - CODE_LEN + i)?0 = (BASE + PREFIX_LEN + i)?0;
branch_if (i := i + 1) < CODE_LEN: copy
}
printString(BASE);
let inaddr = BASE - CODE_LEN;
let outaddr = B64_BASE;
let count = (CODE_LEN + LEN) / 3;
loop blk {
let three =
((inaddr?0) as i32 << 16) |
(((inaddr+1)?0) as i32 << 8) |
((inaddr+2)?0) as i32;
let i = 24;
loop ch {
let x = three >> (i := i - 6) & 63;
outaddr?0 = x + if x < 26 {
65
} else {
if x < 52 {
71
} else {
if x < 62 {
-4
} else {
if x < 63 {
-19
} else {
-16
}
}
}
};
outaddr = outaddr + 1;
branch_if i > 0 : ch
}
inaddr = inaddr + 3;
branch_if (count := count - 1) > 0 : blk
}
printString(B64_BASE);
}
data 0x20000 {
i8(12, 4) "https://exoticorn.github.io/microw8/v0.1.1/#" i8(0)
i8(
0x1,0xa,0x8c,0x2,0x1,0x89,0x2,0x1,0x7,0x7f,0x41,0x0,0x28,0x2,0x40,0x41,
0x0,0x4a,0x4,0x40,0xf,0xb,0x41,0x0,0x21,0x0,0x3,0x40,0x41,0x80,0x80,0x8,
0x41,0x9c,0x2,0x6b,0x20,0x0,0x6a,0x41,0x80,0x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b,0xcb,0x2
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment