Yesterday, I implemented the "ElseIf" directive into my programming language. Here is an example of how to use it:
The 32-bit Windows executable is available as the "months.exe" file in this ZIP-archive.
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=1
days:=31
ElseIf month=2
AsmStart
jmp enterTheYearString$
enterTheYearString:
db "Enter the year:",10,0
enterTheYearString$:
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 month=3
days:=31
ElseIf month=4
days:=30
ElseIf month=5
days:=31
ElseIf month=6
days:=30
ElseIf month=7 | month=8
days:=31
ElseIf month=9
days:=30
ElseIf month=10
days:=31
ElseIf month=11
days:=30
ElseIf month=12
days:=31
Else
AsmStart
jmp invalidDateString$
invalidDateString:
db "Next time you open this program, please enter a natural number between 1 and 12.",10,0
invalidDateString$:
invoke printf,invalidDateString
invoke system,_pause
invoke exit,1
AsmEnd
EndIf
AsmStart
pushIntToStack days
jmp numberOfDaysString$
numberOfDaysString:
db "The month with that ordinal number has %d days.",10,0
numberOfDaysString$:
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