Translates the B programming language into assembly for Z80, 8086, 8080, and 8085 targets. B is a typeless systems programming language — the predecessor of C — where all data is a 16-bit machine word.
| Binary | Target CPU | Runtime | Pointer Size |
| hcbcomp-z80 | Zilog Z80 | CP/M, MSX-DOS | 16-bit |
| hcbcomp-8086 | Intel 8086 | MS-DOS (.COM) | 16-bit |
| hcbcomp-8086exe | Intel 8086 | MS-DOS (.EXE) | 32-bit (far) |
| hcbcomp-8080 | Intel 8080 | CP/M | 16-bit |
| hcbcomp-8085 | Intel 8085 | CP/M | 16-bit |
Usage
hcbcomp-{z80,8086,8080,8085} [options] <input.b>
Options:
-o <file> Output assembly file (default: a.s)
-I <dir> Add include directory for preprocessor
--help, -h Show help
Compilation Pipeline
source.b
↓
[Preprocessor] → #define, #ifdef, #include
↓
[Compiler] → Lexer → Parser → Code Generator
↓
[Peephole] → Instruction-level optimization
↓
[Output] → Assembly (.s) file
Calling Convention
| Aspect | Convention |
| Parameter passing | Stack, right-to-left (C convention) |
| Evaluation order | Right-to-left (two-pass fseek, no reversal step) |
| Stack cleanup | Caller cleans (add sp, n*2) |
| Return value | HL (Z80) / AX (8086) |
| Frame pointer | IX (Z80) / BP (8086) / BC (8080/8085) |
Peephole Optimizer
| Target | Pattern | Before | After | Gain |
| Z80 | Local load | 9 instr | 2 instr (ld r,[ix+N]) | -7 |
| Z80 | Local store (imm) | 12 instr | 3 instr | -9 |
| Z80 | Stack cleanup | ld hl,N; add hl,sp; ld sp,hl | inc sp×N | -4B |
| Z80 | Reg copy | push bc; pop hl | ld h,b; ld l,c | -7T |
| Z80 | Swap around inc sp | ex de,hl; inc sp×N; ex de,hl | inc sp×N | -4B |
| 8086 | LEA+deref | 3 instr | 1 instr (mov ax,[bp+N]) | -2 |
| 8086 | Global deref | 3 instr | 1 instr (mov ax,[label]) | -2 |
| 8086 | Store imm to local | 5 instr | 1 instr (mov word [bp+N],imm) | -4 |
| 8086 | Push/Pop copy | 2 instr | 1 instr (mov reg,reg) | -1 |
| 8086 | Zero register | mov ax,0 | xor ax,ax | -1B |
| 8086exe | 32-bit push/pop | 4 instr | 2 instr (mov cx,dx; mov bx,ax) | -2 |
| 8086exe | LEA+deref | 3 instr | 1 instr | -2 |
| 8086exe | Zero reg (dx) | mov dx,0 | xor dx,dx | -1B |
| 8086exe | 32-bit neg | not ax;not dx;add ax,1;adc dx,0 | neg dx;neg ax;sbb dx,0 | -2B |
| 8080/8085 | FP copy | push h; pop b | mov b,h; mov c,l | -10T |
| 8080/8085 | Store imm | push h; lxi h,N; pop d; xchg | xchg; lxi h,N; xchg | -1B -16T |
B Language Quick Reference
| Feature | Syntax |
| Comments | /* block */ // line |
| Global variable | var; arr[256]; |
| Local variable | auto x, y; |
| External symbol | extrn printf; |
| Function | name(p1, p2) { ... } |
| if/else | if (x) stmt; else stmt; |
| while | while (x) stmt; |
| for | for (init; cond; incr) stmt; |
| return | return expr; |
| break | break; |
| Arithmetic | + - * / % ++ -- |
| Comparison | < > <= >= == != |
| Logical | && || ! |
| Bitwise | & | ^ ~ << >> |
| Assignment | = += -= *= /= %= &= |= ^= |
| Preprocessor | #define #ifdef #ifndef #include |
| Inline assembly | asm("ld a, 0"); |
[Full B Language Reference] ·
[Peephole Details] ·
[Calling Convention]