EuroAssembler Index Manual Download Source Macros


Sitemap Links Forum Tests Projects

tlinabi.htm

This program is designated for demonstration and testing of the base functions from 64bit Linux Application Programming Interface macrolibrary linapi.htm : LinABI, GetArgCount, GetArg, StdInput, StdOutput, TerminateProgram.

This version of EuroAssembler does not directly support Linux ELF executable yet, that is why it uses COFF and an 3rd-party Linux linker ld must be employed here. Tested on 64bit Ubuntu 16.
Format
Linux 64bit
Platform
Linux
Build
wine euroasm.exe tlinabi.htm ld tlinabi.obj -o tlinabi -e Main
Run
./tlinabi arg1 arg2 ...
See also
tlinapi.htm.
        EUROASM CPU=X64
tlinabi PROGRAM Format=COFF, Width=64, Entry=Main:
         INCLUDE linabi.htm, cpuext%^WIDTH.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

▲Back to the top▲