diff --git a/a b/a deleted file mode 100755 index 27d2ae3..0000000 Binary files a/a and /dev/null differ diff --git a/a.nasm b/a.nasm deleted file mode 100644 index c40fca1..0000000 --- a/a.nasm +++ /dev/null @@ -1,67 +0,0 @@ -global _start -segment .text -print: - mov r9, -3689348814741910323 - sub rsp, 40 - mov BYTE [rsp+31], 10 - lea rcx, [rsp+30] -.L2: - mov rax, rdi - lea r8, [rsp+32] - mul r9 - mov rax, rdi - sub r8, rcx - shr rdx, 3 - lea rsi, [rdx+rdx*4] - add rsi, rsi - sub rax, rsi - add eax, 48 - mov BYTE [rcx], al - mov rax, rdi - mov rdi, rdx - mov rdx, rcx - sub rcx, 1 - cmp rax, 9 - ja .L2 - lea rax, [rsp+32] - mov edi, 1 - sub rdx, rax - xor eax, eax - lea rsi, [rsp+32+rdx] - mov rdx, r8 - mov rax, 1 - syscall - add rsp, 40 - ret -_start: - ; -- PUSH 35 - mov rax, 35 - push rax - ; -- PUSH 34 - mov rax, 34 - push rax - ; -- PLUS - pop rax - pop rbx - add rax, rbx - push rax - ; -- PRINT - pop rdi - call print - ; -- PUSH 500 - mov rax, 500 - push rax - ; -- PUSH 80 - mov rax, 80 - push rax - ; -- MINUS - pop rax - pop rbx - sub rbx, rax - push rbx - ; -- PRINT - pop rdi - call print - mov rax, 60 - mov rdi, 0 - syscall diff --git a/a.o b/a.o deleted file mode 100644 index 043db0f..0000000 Binary files a/a.o and /dev/null differ diff --git a/src/compile/linux_x86_64.rs b/src/compile/linux_x86_64.rs index a86957f..9440f56 100644 --- a/src/compile/linux_x86_64.rs +++ b/src/compile/linux_x86_64.rs @@ -81,6 +81,17 @@ pub fn compile(tokens: Vec, args: Args) -> Result<()>{ writeln!(writer, " sub rbx, rax")?; writeln!(writer, " push rbx")?; }, + OpType::Equals => { + writeln!(writer, " ; -- EQUALS")?; + writeln!(writer, " mov rcx, 0")?; + writeln!(writer, " mov rdx, 1")?; + writeln!(writer, " pop rax")?; + writeln!(writer, " pop rbx")?; + writeln!(writer, " cmp rax, rbx")?; + writeln!(writer, " cmove rcx, rdx")?; + writeln!(writer, " push rcx")?; + + }, OpType::Print => { writeln!(writer, " ; -- PRINT")?; writeln!(writer, " pop rdi")?; diff --git a/src/constants.rs b/src/constants.rs index 1d076fd..ae4e086 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -5,9 +5,16 @@ pub enum OpType { Pop, Minus, Plus, + Equals, Print } + +// #[derive(Debug)] +// pub enum OpType { + +// } + #[derive(Debug)] pub struct Operator { pub typ: OpType, diff --git a/src/interpret/linux_x86_64.rs b/src/interpret/linux_x86_64.rs index 661e83c..26ce712 100644 --- a/src/interpret/linux_x86_64.rs +++ b/src/interpret/linux_x86_64.rs @@ -30,6 +30,13 @@ pub fn run(tokens: Vec) -> Result<(), &'static str>{ let b = stack_pop(&mut stack)?; stack.push(b - a); }, + OpType::Equals => { + let a = stack_pop(&mut stack)?; + let b = stack_pop(&mut stack)?; + stack.push((a == b) as i32); + + }, + OpType::Print => { let a = stack_pop(&mut stack)?; println!("{a}"); diff --git a/src/parser.rs b/src/parser.rs index 1f9ff1f..b6f9fe2 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -23,11 +23,12 @@ impl Parser { let num = t.parse::().unwrap(); tokens.push(Operator::new(OpType::Push, num)); }, - + "pop" => tokens.push(Operator::new(OpType::Pop, 0)), "+" => tokens.push(Operator::new(OpType::Plus, 0)), "-" => tokens.push(Operator::new(OpType::Minus, 0)), "print" => tokens.push(Operator::new(OpType::Print, 0)), + "=" => tokens.push(Operator::new(OpType::Equals, 0)), t => { diff --git a/test.mcl b/test.mcl index a7c4dc8..663c870 100644 --- a/test.mcl +++ b/test.mcl @@ -1,3 +1,3 @@ -35 34 + printas +35 34 + 69 = print 500 80 - print \ No newline at end of file diff --git a/x86_64-intel-manual.pdf b/x86_64-intel-manual.pdf new file mode 100644 index 0000000..d6ab1b7 Binary files /dev/null and b/x86_64-intel-manual.pdf differ