Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ unary = deref identifier
| "(" expr ")"
| identifier
| integer
op = "+" | "-" | "&" | "|" | "^" | "<<" | ">>"
op = "+" | "-" | "*" | "/" | "&" | "|" | "^" | "<<" | ">>"
| "==" | "!=" | "<" | ">" | "<=" | ">="
```

Expand Down
28 changes: 28 additions & 0 deletions examples/test_division.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
int x;
int y;
int result;

void test_division()
{
x = 100;
y = 3;
result = x / y;

print_num = result;
print_i16();
print_newline();

x = 50;
y = 5;
result = x / y;

print_num = result;
print_i16();
print_newline();
}

void _start()
{
test_division();
while( 1 ){ }
}
2 changes: 2 additions & 0 deletions lint/lint.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef int64_t i64;
_( TOK_SUB, "-", 65533 )\
_( TOK_ADD, "+", 65531 )\
_( TOK_MUL, "*", 65530 )\
_( TOK_DIV, "/", 65535 )\
_( TOK_OR, "|", 76 )\
_( TOK_XOR, "^", 46 )\
_( TOK_SHL, "<<", 132 )\
Expand Down Expand Up @@ -405,6 +406,7 @@ static bool tok_oper_is(void)
tok_kw_is(TOK_ADD) ||
tok_kw_is(TOK_SUB) ||
tok_kw_is(TOK_MUL) ||
tok_kw_is(TOK_DIV) ||
tok_kw_is(TOK_ADDR) || // "AND" in this context
tok_kw_is(TOK_OR) ||
tok_kw_is(TOK_XOR) ||
Expand Down
17 changes: 15 additions & 2 deletions sectorc.s
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
%define TOK_SUB 65533
%define TOK_ADD 65531
%define TOK_MUL 65530
%define TOK_DIV 65535
%define TOK_AND 65526
%define TOK_OR 76
%define TOK_XOR 46
Expand Down Expand Up @@ -247,7 +248,18 @@ _found:

pop bx ; restore 16-bit of machine-code
cmp bh,0xc0 ; detect the special case for comparison ops
je emit_cmp_op
cmp bh,0xd0 ; detect division op
jne emit_op

; division operator inline
mov ax,0xd231 ; code for "xor dx,dx"
stosw ; emit
mov ax,0xf1f7 ; code for "div cx"
stosw ; emit
pop ds
ret

emit_cmp_op:
mov ax,0xc839 ; code for "cmp ax,cx"
stosw ; emit
Expand All @@ -258,7 +270,7 @@ emit_cmp_op:
;; [fall-through]

emit_op:
mov ax,bx
xchg ax,bx ; 1 byte instead of mov ax,bx (2 bytes)
stosw ; emit machine code for op
pop ds
ret
Expand Down Expand Up @@ -402,7 +414,8 @@ getch_done:
binary_oper_tbl:
dw TOK_ADD,0xc103 ; add ax,cx
dw TOK_SUB,0xc12b ; sub ax,cx
dw TOK_MUL,0xe1f7 ; mul ax,cx
dw TOK_MUL,0xe1f7 ; mul cx
dw TOK_DIV,0xd0f1 ; div cx (marker: 0xd0, low byte is F1 for "div cx")
dw TOK_AND,0xc123 ; and ax,cx
dw TOK_OR,0xc10b ; or ax,cx
dw TOK_XOR,0xc133 ; xor ax,cx
Expand Down