Implement binary logical expressions
This commit is contained in:
@@ -10,7 +10,8 @@
|
|||||||
# The first parameter is in 88, the second in 84 and so forth.
|
# The first parameter is in 88, the second in 84 and so forth.
|
||||||
# - Unary negate operation, e.g. -5.
|
# - Unary negate operation, e.g. -5.
|
||||||
# - Unary locical not operation "~".
|
# - Unary locical not operation "~".
|
||||||
# - Binary addition "+".
|
# - Binary addition "+" and multiplication "*".
|
||||||
|
# - Binary logical operations: & (and), or and xor.
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
|
|
||||||
@@ -86,6 +87,15 @@ asm_neg: .string "\tneg "
|
|||||||
.type asm_not, @object
|
.type asm_not, @object
|
||||||
asm_not: .string "\tnot "
|
asm_not: .string "\tnot "
|
||||||
|
|
||||||
|
.type asm_and, @object
|
||||||
|
asm_and: .string "\tand "
|
||||||
|
|
||||||
|
.type asm_or, @object
|
||||||
|
asm_or: .string "\tor "
|
||||||
|
|
||||||
|
.type asm_xor, @object
|
||||||
|
asm_xor: .string "\txor "
|
||||||
|
|
||||||
.type asm_comma, @object
|
.type asm_comma, @object
|
||||||
asm_comma: .string ", "
|
asm_comma: .string ", "
|
||||||
|
|
||||||
@@ -695,6 +705,15 @@ begin
|
|||||||
li t1, '*'
|
li t1, '*'
|
||||||
beq t0, t1, .compile_expression_mul
|
beq t0, t1, .compile_expression_mul
|
||||||
|
|
||||||
|
li t1, '&'
|
||||||
|
beq t0, t1, .compile_expression_and
|
||||||
|
|
||||||
|
li t1, 'o'
|
||||||
|
beq t0, t1, .compile_expression_or
|
||||||
|
|
||||||
|
li t1, 'x'
|
||||||
|
beq t0, t1, .compile_expression_xor
|
||||||
|
|
||||||
# Unknown binary operator.
|
# Unknown binary operator.
|
||||||
unimp
|
unimp
|
||||||
|
|
||||||
@@ -728,6 +747,51 @@ begin
|
|||||||
|
|
||||||
goto .compile_expression_end;
|
goto .compile_expression_end;
|
||||||
|
|
||||||
|
.compile_expression_and:
|
||||||
|
_advance_token(1);
|
||||||
|
_compile_binary_rhs();
|
||||||
|
|
||||||
|
# Execute the operation.
|
||||||
|
_write_z(@asm_and);
|
||||||
|
_write_register('t', 0);
|
||||||
|
_write_z(@asm_comma);
|
||||||
|
_write_register('t', 0);
|
||||||
|
_write_z(@asm_comma);
|
||||||
|
_write_register('t', 1);
|
||||||
|
_write_c('\n');
|
||||||
|
|
||||||
|
goto .compile_expression_end;
|
||||||
|
|
||||||
|
.compile_expression_or:
|
||||||
|
_advance_token(1);
|
||||||
|
_compile_binary_rhs();
|
||||||
|
|
||||||
|
# Execute the operation.
|
||||||
|
_write_z(@asm_or);
|
||||||
|
_write_register('t', 0);
|
||||||
|
_write_z(@asm_comma);
|
||||||
|
_write_register('t', 0);
|
||||||
|
_write_z(@asm_comma);
|
||||||
|
_write_register('t', 1);
|
||||||
|
_write_c('\n');
|
||||||
|
|
||||||
|
goto .compile_expression_end;
|
||||||
|
|
||||||
|
.compile_expression_xor:
|
||||||
|
_advance_token(1);
|
||||||
|
_compile_binary_rhs();
|
||||||
|
|
||||||
|
# Execute the operation.
|
||||||
|
_write_z(@asm_xor);
|
||||||
|
_write_register('t', 0);
|
||||||
|
_write_z(@asm_comma);
|
||||||
|
_write_register('t', 0);
|
||||||
|
_write_z(@asm_comma);
|
||||||
|
_write_register('t', 1);
|
||||||
|
_write_c('\n');
|
||||||
|
|
||||||
|
goto .compile_expression_end;
|
||||||
|
|
||||||
.compile_expression_end:
|
.compile_expression_end:
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@@ -10,7 +10,8 @@
|
|||||||
# The first parameter is in 88, the second in 84 and so forth.
|
# The first parameter is in 88, the second in 84 and so forth.
|
||||||
# - Unary negate operation, e.g. -5.
|
# - Unary negate operation, e.g. -5.
|
||||||
# - Unary locical not operation "~".
|
# - Unary locical not operation "~".
|
||||||
# - Binary addition "+".
|
# - Binary addition "+" and multiplication "*".
|
||||||
|
# - Binary logical operations: & (and), or and xor.
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
|
|
||||||
@@ -86,6 +87,15 @@ asm_neg: .string "\tneg "
|
|||||||
.type asm_not, @object
|
.type asm_not, @object
|
||||||
asm_not: .string "\tnot "
|
asm_not: .string "\tnot "
|
||||||
|
|
||||||
|
.type asm_and, @object
|
||||||
|
asm_and: .string "\tand "
|
||||||
|
|
||||||
|
.type asm_or, @object
|
||||||
|
asm_or: .string "\tor "
|
||||||
|
|
||||||
|
.type asm_xor, @object
|
||||||
|
asm_xor: .string "\txor "
|
||||||
|
|
||||||
.type asm_comma, @object
|
.type asm_comma, @object
|
||||||
asm_comma: .string ", "
|
asm_comma: .string ", "
|
||||||
|
|
||||||
@@ -695,6 +705,15 @@ begin
|
|||||||
li t1, '*'
|
li t1, '*'
|
||||||
beq t0, t1, .compile_expression_mul
|
beq t0, t1, .compile_expression_mul
|
||||||
|
|
||||||
|
li t1, '&'
|
||||||
|
beq t0, t1, .compile_expression_and
|
||||||
|
|
||||||
|
li t1, 'o'
|
||||||
|
beq t0, t1, .compile_expression_or
|
||||||
|
|
||||||
|
li t1, 'x'
|
||||||
|
beq t0, t1, .compile_expression_xor
|
||||||
|
|
||||||
# Unknown binary operator.
|
# Unknown binary operator.
|
||||||
unimp
|
unimp
|
||||||
|
|
||||||
@@ -728,6 +747,51 @@ begin
|
|||||||
|
|
||||||
goto .compile_expression_end;
|
goto .compile_expression_end;
|
||||||
|
|
||||||
|
.compile_expression_and:
|
||||||
|
_advance_token(1);
|
||||||
|
_compile_binary_rhs();
|
||||||
|
|
||||||
|
# Execute the operation.
|
||||||
|
_write_z(@asm_and);
|
||||||
|
_write_register('t', 0);
|
||||||
|
_write_z(@asm_comma);
|
||||||
|
_write_register('t', 0);
|
||||||
|
_write_z(@asm_comma);
|
||||||
|
_write_register('t', 1);
|
||||||
|
_write_c('\n');
|
||||||
|
|
||||||
|
goto .compile_expression_end;
|
||||||
|
|
||||||
|
.compile_expression_or:
|
||||||
|
_advance_token(1);
|
||||||
|
_compile_binary_rhs();
|
||||||
|
|
||||||
|
# Execute the operation.
|
||||||
|
_write_z(@asm_or);
|
||||||
|
_write_register('t', 0);
|
||||||
|
_write_z(@asm_comma);
|
||||||
|
_write_register('t', 0);
|
||||||
|
_write_z(@asm_comma);
|
||||||
|
_write_register('t', 1);
|
||||||
|
_write_c('\n');
|
||||||
|
|
||||||
|
goto .compile_expression_end;
|
||||||
|
|
||||||
|
.compile_expression_xor:
|
||||||
|
_advance_token(1);
|
||||||
|
_compile_binary_rhs();
|
||||||
|
|
||||||
|
# Execute the operation.
|
||||||
|
_write_z(@asm_xor);
|
||||||
|
_write_register('t', 0);
|
||||||
|
_write_z(@asm_comma);
|
||||||
|
_write_register('t', 0);
|
||||||
|
_write_z(@asm_comma);
|
||||||
|
_write_register('t', 1);
|
||||||
|
_write_c('\n');
|
||||||
|
|
||||||
|
goto .compile_expression_end;
|
||||||
|
|
||||||
.compile_expression_end:
|
.compile_expression_end:
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -1229,6 +1293,6 @@ begin
|
|||||||
_read_file(@source_code, 81920);
|
_read_file(@source_code, 81920);
|
||||||
_compile();
|
_compile();
|
||||||
|
|
||||||
_exit(2 * 3);
|
_exit(0);
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user