Anyway, here is an example of how conditional operators and string constants (things I've added to AEC recently) can make the code significantly shorter:
That dragitz who forked my repository on GitHub apparently won't cooperate with me any more. But, anyway, I've introduced a few hard-to-fix problems in my code by adding new features. First of all, the AST diagrams that are produced for ternary operators are next to useless. Second, perhaps even more damaging, there is a [url=https://github.com/FlatAssembler/Arithme...r/issues/1]bug[/url] that prevents my implementation of QuickSort to be compiled using the newest version of the compiler (HybridSort and MergeSort are unaffected), and it's not easy to fix. I've chosen a fundamentally wrong method of compiling long ago and it would take very long to think of a better algorithm and implement it.
Code:
AsmStart
debug=0
macro pushIntToStack x
{
sub esp,4
fld dword [x]
fistp dword [esp]
}
macro pushPointerToStack x
{
sub esp,4
lea ebx,[x]
mov [esp],ebx
}
macro pushStringToStack x
{
sub esp,4
mov dword [esp],x
}
format PE console
entry start
include 'win32a.inc'
section '.text' code executable
start:
jmp enterNumber$
enterNumber db "Enter the ordinal number of the month.",10,0
enterNumber$:
pushStringToStack enterNumber
call [printf]
pushPointerToStack month
jmp floatSign$
floatSign db "%f",0
floatSign$:
pushStringToStack floatSign
call [scanf]
AsmEnd
If month=2
enterTheYearString<="Enter the year:",10,0
AsmStart
invoke printf,enterTheYearString
pushPointerToStack year
pushStringToStack floatSign
call [scanf]
AsmEnd
If mod(year,4)=0 & not(mod(year,400)=0)
days:=29
Else
days:=28
EndIf
ElseIf mod(month,1)=0 & month>0 & month<13
days:= month=1? 31 : month=3? 31 : month=4? 30 : month=5? 31 : month=6? 30 : (month=7 | month=8)? 31 : month=9? 30 : month=10? 31 : month=11? 30 : 31
Else
invalidDateString<="Next time you open this program, please enter a natural number between 1 and 12.",10,0
AsmStart
invoke printf,invalidDateString
invoke system,_pause
invoke exit,1
AsmEnd
EndIf
numberOfDaysString<="The month with that ordinal number has %d days.",10,0
AsmStart
pushIntToStack days
invoke printf,numberOfDaysString
invoke system,_pause
invoke exit,0
_pause db "PAUSE",0
section '.rdata' readable writable
result dd ?
month dd ?
days dd ?
year dd ?
section '.idata' data readable import
library msvcrt,'msvcrt.dll'
import msvcrt,printf,'printf',system,'system',exit,'exit',scanf,'scanf'
AsmEnd