diff --git a/src/libasr/codegen/wasm_to_x86.cpp b/src/libasr/codegen/wasm_to_x86.cpp index 5b8f293b54..21d08da8bb 100644 --- a/src/libasr/codegen/wasm_to_x86.cpp +++ b/src/libasr/codegen/wasm_to_x86.cpp @@ -55,6 +55,7 @@ class X86Visitor : public WASMDecoder, switch (func_index) { case 0: { // print_i32 m_a.asm_call_label("print_i32"); + m_a.asm_pop_r32(X86Reg::eax); break; } case 1: { // print_i64 diff --git a/src/libasr/codegen/x86_assembler.cpp b/src/libasr/codegen/x86_assembler.cpp index 83be127b03..8c97da3840 100644 --- a/src/libasr/codegen/x86_assembler.cpp +++ b/src/libasr/codegen/x86_assembler.cpp @@ -51,7 +51,7 @@ void emit_elf32_header(X86Assembler &a, uint32_t p_flags) { a.asm_dw_imm16(2); // e_type a.asm_dw_imm16(3); // e_machine a.asm_dd_imm32(1); // e_version - a.asm_dd_label("e_entry"); // e_entry + a.asm_dd_label("_start"); // e_entry a.asm_dd_label("e_phoff"); // e_phoff a.asm_dd_imm32(0); // e_shoff a.asm_dd_imm32(0); // e_flags @@ -80,8 +80,7 @@ void emit_elf32_header(X86Assembler &a, uint32_t p_flags) { } void emit_elf32_footer(X86Assembler &a) { - a.add_var("e_entry", a.get_defined_symbol("_start").value); - a.add_var("filesize", a.pos()-a.origin()); + a.add_var_size("filesize"); } void emit_exit(X86Assembler &a, const std::string &name, diff --git a/src/libasr/codegen/x86_assembler.h b/src/libasr/codegen/x86_assembler.h index 3da7e23076..8eee7cbcb1 100644 --- a/src/libasr/codegen/x86_assembler.h +++ b/src/libasr/codegen/x86_assembler.h @@ -362,7 +362,8 @@ class X86Assembler { m_asm_code = "BITS 64\n"; emit(" ", "org " + i2s((uint64_t)m_origin) + "\n"); // specify origin info } else { - m_asm_code = "BITS 32\n\n"; + m_asm_code = "BITS 32\n"; + emit(" ", "org " + i2s(m_origin) + "\n"); // specify origin info } #endif } diff --git a/src/lpython/tests/test_asm.cpp b/src/lpython/tests/test_asm.cpp index b490d5a6a8..3ae983276c 100644 --- a/src/lpython/tests/test_asm.cpp +++ b/src/lpython/tests/test_asm.cpp @@ -65,6 +65,7 @@ TEST_CASE("Store and get instructions") { std::string asm_code = a.get_asm(); std::string ref = S(R"""( BITS 32 + org 0x08048000 pop eax jz 0x0d @@ -300,6 +301,7 @@ TEST_CASE("Memory operand") { std::string asm_code = a.get_asm(); std::string ref = S(R"""( BITS 32 + org 0x08048000 inc [ebx] inc [ebx+3] @@ -369,6 +371,7 @@ TEST_CASE("elf32 binary") { std::string asm_code = a.get_asm(); std::string ref = S(R"""( BITS 32 + org 0x08048000 ehdr: db 0x7f @@ -390,7 +393,7 @@ BITS 32 dw 0x0002 dw 0x0003 dd 0x00000001 - dd e_entry + dd _start dd e_phoff dd 0x00000000 dd 0x00000000 @@ -444,10 +447,7 @@ e_phoff equ 0x00000034 mov ebx, 0x00000000 int 0x80 -e_entry equ 0x08048061 - - -filesize equ 0x00000088 +filesize equ $ - $$ )"""); CHECK(asm_code == ref);