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 32-bit Linux Application Programming Interface macrolibrary linapi.htm : LinAPI, GetArgCount, GetArg, StdInput, StdOutput, TerminateProgram.

Format
Linux 32 bit
Platform
Linux
Build
euroasm.exe tlinapi.htm
Run
./tlinapi.x arg1 arg2 ...
See also
tlinabi.htm.
        EUROASM
tlinapi PROGRAM Format=ELFX, Width=32, Entry=Main:
         INCLUDE linapi.htm, cpuext32.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▲