global sysWrite, sysRead, sysExit, sysExit0, putChar, getChar ; códigos das chamadas ao sistema de operação (Linux) SYS_EXIT equ 1 SYS_READ equ 3 SYS_WRITE equ 4 ; INTR de chamada ao sistema LINUXCALL equ 0x80 ; section .code ; sysWrite - write bytes to the standard output channel ; ecx <- has the address of the bytes to be written ; edx <- has the number of bytes to write sysWrite: push eax push ebx mov ebx, 1 ; write to standard output mov eax, SYS_WRITE int LINUXCALL pop ebx pop eax ret ; sysRead - read bytes from the standard input channel ; ecx <- has the address of the bytes that are read ; edx <- max number of bytes to read sysRead: push eax push ebx mov ebx, 0 ; read from standar input mov eax, SYS_READ int LINUXCALL pop ebx pop eax ret ; sysExit - terminate program ; ebx has the exit value/code (needed by the exit sys call) sysExit: push eax mov eax, SYS_EXIT int LINUXCALL pop eax ret hlt ; in case something goes wrong ; sysExit0 - terminate program (returning the 0 exit ; status to the OS) sysExit0: push eax push ebx mov ebx, 0 ; exit status mov eax, SYS_EXIT int LINUXCALL pop ebx pop eax ret hlt ; in case something goes wrong ; putChar - write one character to the standard output ; al <- has the character no write putChar: push ecx push edx push eax ; since al has the character, the character ; is now on the top of the stack mov ecx, esp ; address of the character mov edx, 1 ; write just one character call sysWrite pop eax pop edx pop ecx ret ; getChar - read one character from the standard input ; al -> has the character that was read getChar: push ecx push edx push eax mov ecx, esp ; the character will be put on ; the top of the stack mov edx, 1 ; only character is read call sysRead pop eax ; eax receives its original value, but the ; least significant byte has now the ; character that was read pop edx pop ecx ret