EuroAssembler Index Manual Download Source Macros


Sitemap Links Forum Tests Projects

tlinapi.htm

This program is designated for demonstration and testing of the base functions from 32bit Linux Application Programming Interface macrolibrary linapi.htm : LinAPI, 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 32bit
Platform
Linux
Build
wine euroasm.exe tlinapi.htm ld tlinapi.obj -o tlinapi -e Main -m elf_i386
Run
./tlinapi arg1 arg2 ...
See also
tlinabi.htm.
        EUROASM
tlinapi PROGRAM Format=COFF, Width=32, Entry=Main:
         INCLUDE linapi.htm, cpuext%^WIDTH.htm
[.text]
Main:    PROC
         GetArgCount     ; Count the command-line arguments.
         JC .Abort:
         MOV [ArgCount],ECX
         MOV EAX,ECX
         StoD ArgCount$  ; Convert binary number EAX 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 EBX,[ArgCount]
         JA .EchoInp:    ; Jump when all arguments have been echoed.
         MOV EAX,EBX
         StoD ArgNr$     ; Convert binary number EAX to a decimal string.
         SUB EAX,EAX
         STOSB           ; Zero-terminate the string.
         GetArg EBX      ; 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 ESI, Size=ECX, 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=ECX, 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  DD D
ArgCount$ DB 6*B
ArgNr$    DB 6*B
ArgSize$  DB 6*B
BufSize$  DB 6*B
Buffer    DB 128*B
      ENDPROGRAM tlinapi

▲Back to the top▲