Hey, guys!
New here. I've just made a simple web-app that attempts to convert arithmetic expressions to i486-compatible assembly: Arithmetic expression to assembly converter
(My website sleeps from 22h to 23h GTM+1.)
I've tried to test it (using Flat Assembler), and to me it seems like it produces correct results. However, I am not a professional programmer, so I would like to hear from some experts (and I guess people who know the details of a program such as DosBox are experts on those things).
Hi,
It's an interesting idea and actually it can be quite useful.
Just a few observations:
1. It treats everything as floating point. So the simple arithmetic expression '1+1' generates single precision FPU code instead of more reasonable integer code. So the code is only 486DX+ compatible and cannot work on 486SX.
2. '123456789.123456789 + 123456789.123456789' also generates single precision FPU code though in this case double or even extended precision (or an option) could be more useful.
Otherwise the code seems to be OK although not the most optimized (finit is a speed killer for small routines and also resets control word. I would rather omit it).
So, do you think I am good at programming? Is it worth continuing?
If so, what would you recommend me to learn next? I've made that in JavaScript, and that's the only programming language I know well enough to be able to do that in it.
Anyway, I've improved my compiler using the Duktape framework to be able not only to translate single directives from my own programming language into Assembly, but to also be able to translate entire simple programs stored in files. Here is one of the first programs I've written in the first programming language I've made myself:
1;Advanced example: implementing the permutation algorithm. 2AsmStart 3 debug=0 4 macro pushIntToStack x 5 { 6 sub esp,4 7 fld dword [x] 8 fistp dword [esp] 9 } 10 macro pushPointerToStack x 11 { 12 sub esp,4 13 lea ebx,[x] 14 mov [esp],ebx 15 } 16 macro pushStringToStack x 17 { 18 sub esp,4 19 mov dword [esp],x 20 } 21 format PE console 22 entry start 23 24 include 'win32a.inc' 25 26 section '.text' code executable 27 start: 28 jmp enterNumber$ 29 enterNumber db "Enter a whole number (1 - 1'000'000).",10,0 30 enterNumber$: 31 pushStringToStack enterNumber 32 call [printf] 33 pushPointerToStack original 34 jmp floatSign$ 35 floatSign db "%f",0 36 floatSign$: 37 pushStringToStack floatSign 38 call [scanf] 39 jmp permutationString$ 40 permutationString db "The permutations of its digits are:",10,0 41 permutationString$: 42 pushStringToStack permutationString 43 call [printf] 44AsmEnd 45numberOfDigits:=0 46i:=0 47While i<10 48 countDigits[i]:=0 49 i:=i+1 50EndWhile 51While original>0 52 numberOfDigits:= numberOfDigits + 1 53 lastDigit:= mod( original , 10 ) 54 countDigits[ lastDigit ]:=countDigits( lastDigit ) + 1 55 original:= (original - lastDigit) / 10 56EndWhile 57AsmStart 58 if debug=1 59AsmEnd 60 i:=0
The source code of the compiler, as well as the instructions on how to compile it and use it, can be downloaded here.
So, what do you think about it? Is it worth continuing developing it?
I am also dreaming about making my own LISP-like language, in which you will able to use both S-expressions and infix-expressions (since S-expressions come handy in array and string-manipulation, and infix-expressions come handy in arithmetic expressions), but I am unlikely to have time to develop it in foreseeable future.