;; ito.asm Input to Output ;; version 0.0.2a ;; ;; Copyright 2016 Kevin G. Austin ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. ;; You may obtain a copy of the License at ;; ;; http://www.apache.org/licenses/LICENSE-2.0 ;; ;; Unless required by applicable law or agreed to in writing, software ;; distributed under the License is distributed on an "AS IS" BASIS, ;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ;; See the License for the specific language governing permissions and ;; limitations under the License. ;; ;; to build : ;; For 32 bit Linux systems ;; nasm -f elf ito.asm && ld -s ito.o -o ito ;; For 64 bit Linux systems ;; nasm -f elf64 ito.asm && ld -s ito.o -o ito ;; ;; Uncomment the next line for 32 bit systems ;; BITS 32 ;; Uncomment the next line for 64 bit systems ;; BITS 64 section .bss charbufr: resb 1 ; reserve 1 byte buffer section .text global _start _start: ;; Loop once for each char of output. charloop: mov eax, 3 ; syscall 3 = read mov bl, 0 ; 0 = stdin mov ecx, charbufr ; pointer to char buffer mov dl, 1 ; read 1 char int 0x80 ; syscall or eax, eax ; test return jle short done ; <= 0 means done mov eax, 4 ; syscall 4 = write mov bl, 1 ; 1 = stdout mov ecx, charbufr ; pointer to char buffer mov dl, 1 ; write 1 char int 0x80 ; syscall or eax, eax ; test return jg short charloop ; > 0 means success so loop done: xor eax, eax ; clear eax inc eax ; set syscall to exit (= 1) int 0x80 ; syscall