Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: April 27, 2024, 11:05 am

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arithmetic Expression Compiler
#36
RE: Arithmetic Expression Compiler
So, yesterday, I made two rather big achievements. First of all, I changed my compiler so that it can also produce assembly code compatible with GNU Assembler. It should now be relatively easy to add even more assemblers, I made the code significantly more modular in the process.
I also finally managed to make a version that can be run in NodeJS, you can download it here.
Here is an example program targeting GNU Assembler, drawing the Sierpinski triangle:
Code:
Syntax GAS
;So, this is an example of how to target GNU Assembler (GAS) using AEC, and how to target Linux.
AsmStart ;What follows is the assembly code produced by CLANG 9.0 on Linux, I don't understand it either, and it's not important.
    .text
    .file   "sierpinski.c"
    .globl  main                    # -- Begin function main
    .p2align    4, 0x90
    .type   main,@function
main:                                   # @main
# %bb.0:
    pushl   %ebp
    movl    %esp, %ebp
    subl    $24, %esp
    movl    $0, -4(%ebp)
    leal    .L.str, %eax
    movl    %eax, (%esp)
    calll   printf
    leal    .L.str.1, %ecx
    movl    %ecx, (%esp)
    leal    n, %ecx
    movl    %ecx, 4(%esp)
    movl    %eax, -8(%ebp)          # 4-byte Spill
    calll   __isoc99_scanf
AsmEnd ;And here goes a program written in AEC, finally.
i:=0
While i<n ;This loop will fill the array "new_array" with zeros, except the point right in the middle, which will be filled with 1.
    If i=n/2-mod(n/2,1) ;So, if i=floor(n/2), except that I didn't put "floor" in my programming language, so I need to paraphrase it.
        new_array(i):=1
    Else
        new_array(i):=0
    EndIf
    i:=i+1
EndWhile
i:=0
While i<n
    j:=0
    While j<n | j=n ;Printing the current state and the new line.
        If j=n
            AsmStart
                .intel_syntax noprefix #Because I don't know anything about att_syntax assembly.
                mov byte ptr [esp+4],'\n' #'\n' is, of course, the new line character (in FlatAssembler, you would need to write 10, the ASCII of '\n').
                .att_syntax #Not important here (my compiler switches to Intel Syntax before outputting anything except inline Assembly), but added for consistency.
            AsmEnd
        ElseIf new_array(j)=1
            AsmStart
                .intel_syntax noprefix
                mov byte ptr [esp+4],'*'
                .att_syntax
            AsmEnd
        Else
            AsmStart
                .intel_syntax noprefix
                mov byte ptr [esp+4],' '
                .att_syntax
            AsmEnd
        EndIf
        charSign<="%c\0" ;If you write "'%c',0", as you write that in FlatAssembler, GAS complains.
        AsmStart
            .intel_syntax noprefix
            lea ebx,dword ptr [charSign]
            mov dword ptr [esp],ebx
            call printf
            .att_syntax
        AsmEnd
        j:=j+1
    EndWhile
    j:=0
    While j<n ;Copying "new_array" into "old_array".
        old_array(j):=new_array(j)
        j:=j+1
    EndWhile
    j:=0
    While j<n
        If j=0 | j=n-1 ;Edges
            new_array(j):=0
        ElseIf old_array(j-1)=old_array(j+1) ;In other words, each cell in the new line in the Sierpinski triangle is the "xor" of its neighbours in the line above it.
            new_array(j):=0
        Else
            new_array(j):=1
        EndIf
        j:=j+1
    EndWhile
    i:=i+1
EndWhile
AsmStart ;Again, assembly code produced by CLANG 9.0 on Linux, I don't understand it either.
    xorl    %ecx, %ecx
    movl    %eax, -12(%ebp)         # 4-byte Spill
    movl    %ecx, %eax
    addl    $24, %esp
    popl    %ebp
    retl
.Lfunc_end0:
    .size   main, .Lfunc_end0-main
                                        # -- End function
    .type   .L.str,@object          # @.str
    .section    .rodata.str1.1,"aMS",@progbits,1
.L.str:
    .asciz  "Enter the number of rows and columns in the Sierpinski triangle.\n"
    .size   .L.str, 67

    .type   .L.str.1,@object        # @.str.1
.L.str.1:
    .asciz  "%f"
    .size   .L.str.1, 3
    .type   n,@object               # @n
    .comm   n,4,4
    .type   i,@object               # @i
    .comm   i,4,4
    .type   j,@object               # @j
    .comm   j,4,4
    .type   result,@object          # @result
    .comm   result,4,4
    .type   old_array,@object       # @old_array
    .comm   old_array,320,4
    .type   new_array,@object       # @new_array
    .comm   new_array,320,4

    .ident  "clang version 9.0.0 (tags/RELEASE_900/final)"
    .section    ".note.GNU-stack","",@progbits
    .addrsig
    .addrsig_sym printf
    .addrsig_sym __isoc99_scanf
    .addrsig_sym n
AsmEnd



Messages In This Thread
Arithmetic Expression Compiler - by FlatAssembler - January 2, 2019 at 3:01 am
RE: Arithmetic Expression Compiler - by bennyboy - January 2, 2019 at 7:15 am
RE: Arithmetic Expression Compiler - by Angrboda - January 2, 2019 at 9:56 am
RE: Arithmetic Expression Compiler - by FlatAssembler - January 3, 2019 at 4:47 am
RE: Arithmetic Expression Compiler - by Angrboda - January 3, 2019 at 9:27 am
RE: Arithmetic Expression Compiler - by FlatAssembler - January 3, 2019 at 12:35 pm
RE: Arithmetic Expression Compiler - by bennyboy - January 3, 2019 at 9:09 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - January 9, 2019 at 5:08 am
RE: Arithmetic Expression Compiler - by bennyboy - January 9, 2019 at 5:09 pm
RE: Arithmetic Expression Compiler - by SteelCurtain - January 9, 2019 at 10:24 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - January 10, 2019 at 8:16 am
RE: Arithmetic Expression Compiler - by bennyboy - January 10, 2019 at 10:33 am
RE: Arithmetic Expression Compiler - by FlatAssembler - January 12, 2019 at 8:02 am
RE: Arithmetic Expression Compiler - by bennyboy - January 12, 2019 at 9:36 am
RE: Arithmetic Expression Compiler - by FlatAssembler - January 31, 2019 at 3:50 am
RE: Arithmetic Expression Compiler - by bennyboy - January 31, 2019 at 8:42 am
RE: Arithmetic Expression Compiler - by FlatAssembler - February 8, 2019 at 2:30 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - May 2, 2019 at 11:00 am
RE: Arithmetic Expression Compiler - by FlatAssembler - May 10, 2019 at 3:53 am
RE: Arithmetic Expression Compiler - by Smaug - May 10, 2019 at 7:45 am
RE: Arithmetic Expression Compiler - by FlatAssembler - May 25, 2019 at 2:28 pm
RE: Arithmetic Expression Compiler - by Smaug - May 31, 2019 at 5:56 am
RE: Arithmetic Expression Compiler - by FlatAssembler - June 1, 2019 at 1:50 am
RE: Arithmetic Expression Compiler - by Smaug - June 1, 2019 at 1:24 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - June 2, 2019 at 7:26 am
RE: Arithmetic Expression Compiler - by Smaug - June 6, 2019 at 4:12 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - June 7, 2019 at 8:01 am
RE: Arithmetic Expression Compiler - by Jehanne - May 31, 2019 at 7:17 am
RE: Arithmetic Expression Compiler - by FlatAssembler - August 17, 2019 at 1:50 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - October 31, 2019 at 12:50 am
RE: Arithmetic Expression Compiler - by FlatAssembler - January 4, 2020 at 9:26 am
RE: Arithmetic Expression Compiler - by FlatAssembler - May 1, 2020 at 12:08 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - May 22, 2020 at 2:40 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - May 27, 2020 at 8:52 am
RE: Arithmetic Expression Compiler - by FlatAssembler - June 14, 2020 at 9:32 am
RE: Arithmetic Expression Compiler - by FlatAssembler - June 18, 2020 at 1:12 pm
RE: Arithmetic Expression Compiler - by arewethereyet - June 18, 2020 at 1:27 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - June 18, 2020 at 3:35 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - June 24, 2020 at 3:59 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - August 22, 2020 at 1:16 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - August 30, 2020 at 4:24 am
RE: Arithmetic Expression Compiler - by BrianSoddingBoru4 - August 30, 2020 at 6:51 am
RE: Arithmetic Expression Compiler - by FlatAssembler - August 30, 2020 at 10:56 am
RE: Arithmetic Expression Compiler - by BrianSoddingBoru4 - August 30, 2020 at 11:37 am
RE: Arithmetic Expression Compiler - by FlatAssembler - August 30, 2020 at 12:02 pm
RE: Arithmetic Expression Compiler - by BrianSoddingBoru4 - August 30, 2020 at 1:09 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - August 30, 2020 at 1:37 pm
RE: Arithmetic Expression Compiler - by Angrboda - August 30, 2020 at 12:14 pm
RE: Arithmetic Expression Compiler - by BrianSoddingBoru4 - August 30, 2020 at 2:01 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - August 30, 2020 at 2:06 pm
RE: Arithmetic Expression Compiler - by BrianSoddingBoru4 - August 30, 2020 at 2:15 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - August 30, 2020 at 4:39 pm
RE: Arithmetic Expression Compiler - by Grandizer - September 3, 2020 at 3:43 pm
RE: Arithmetic Expression Compiler - by BrianSoddingBoru4 - August 30, 2020 at 6:55 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - September 3, 2020 at 12:08 pm
RE: Arithmetic Expression Compiler - by BrianSoddingBoru4 - September 3, 2020 at 3:18 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - September 3, 2020 at 4:51 pm
RE: Arithmetic Expression Compiler - by BrianSoddingBoru4 - September 3, 2020 at 5:06 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - September 4, 2020 at 4:05 am
RE: Arithmetic Expression Compiler - by Angrboda - September 3, 2020 at 3:10 pm
RE: Arithmetic Expression Compiler - by BrianSoddingBoru4 - September 4, 2020 at 4:17 am
RE: Arithmetic Expression Compiler - by FlatAssembler - September 21, 2020 at 3:12 pm
RE: Arithmetic Expression Compiler - by HappySkeptic - September 24, 2020 at 1:12 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - October 5, 2020 at 5:01 pm
RE: Arithmetic Expression Compiler - by HappySkeptic - October 5, 2020 at 9:12 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - October 6, 2020 at 1:55 pm
RE: Arithmetic Expression Compiler - by FlatAssembler - October 18, 2020 at 9:11 am
RE: Arithmetic Expression Compiler - by FlatAssembler - July 17, 2021 at 12:29 pm
RE: Arithmetic Expression Compiler - by arewethereyet - July 17, 2021 at 12:36 pm

Possibly Related Threads...
Thread Author Replies Views Last Post
  Compiler Theory FlatAssembler 5 1019 October 27, 2020 at 10:48 am
Last Post: Angrboda



Users browsing this thread: 1 Guest(s)