This program is designated for demonstration and testing of the base functions from 64bit Linux Application Programming Interface macrolibrary linabi.htm : LinABI, GetArgCount, GetArg, StdInput, StdOutput, TerminateProgram.
EUROASM CPU=X64
tlinabi PROGRAM Format=ELFX, Width=64, Entry=Main:
INCLUDE linabi.htm, cpuext64.htm
[.text]
Main: PROC
GetArgCount ; Count the command-line arguments.
JC .Abort:
MOV [ArgCount],RCX
MOV EAX,ECX
StoD ArgCount$ ; Convert binary number RAX to a decimal string.
JC .Abort:
StdOutput =B"%^PROGRAM launched with ", ArgCount$, =B" arguments:", Eol=Yes
JC .Abort:
SUB EBX,EBX ; EBX will be the ordinal number of each argument.
.EchoArg:CMP RBX,[ArgCount]
JA .EchoInp: ; Jump when all arguments have been echoed.
MOV EAX,EBX
StoD ArgNr$ ; Convert binary number RAX to a decimal string.
SUB EAX,EAX
STOSB ; Zero-terminate the string.
GetArg RBX ; Retrieve EBX-th argument to ESI,ECX.
JC .Abort:
MOV EAX,ECX ; Argument size in bytes.
StoD ArgSize$ ; Convert binary number EAX to a decimal string.
SUB EAX,EAX
STOSB ; Zero-terminate the string.
StdOutput ArgNr$, =B".[", ArgSize$, =B"]: "
StdOutput RSI, Size=RCX, Eol=Yes ; Echo the argument.
JC .Abort:
INC EBX
JMP .EchoArg:
.EchoInp:StdOutput =B"Enter some text: "
StdInput Buffer
JC .Abort:
MOV EAX,ECX ; Text size including CR+LF.
StoD BufSize$ ; Convert binary number EAX to a decimal string.
SUB EAX,EAX
STOSB ; Zero-terminate the string.
StdOutput =B"Entered[", BufSize$, =B"]: "
StdOutput Buffer, Size=RCX, Eol=Yes
JC .Abort:
StdOutput =B"%^PROGRAM terminated."
TerminateProgram Errorlevel=0
.Abort: StdOutput =B"Aborted, some macro returned CF.",Eol=Yes
TerminateProgram Errorlevel=4
ENDP Main:
[.data]
ArgCount DQ Q
ArgCount$ DB 6*B
ArgNr$ DB 6*B
ArgSize$ DB 6*B
BufSize$ DB 6*B
Buffer DB 128*B
ENDPROGRAM tlinabi