RosettaCodeData/Task/Copy-stdin-to-stdout/8086-Assembly/copy-stdin-to-stdout.8086
2023-07-01 13:44:08 -04:00

22 lines
459 B
Text

READ: equ 3Fh ; MS-DOS syscalls
WRITE: equ 40h
BUFSZ: equ 4000h ; Buffer size
cpu 8086
bits 16
org 100h
section .text
read: mov ah,READ ; Read into buffer
xor bx,bx ; From STDIN (file 0)
mov cx,BUFSZ
mov dx,buffer
int 21h
test ax,ax ; Did we read anything?
jz done ; If not, stop
xchg ax,cx ; Write as many bytes as read
mov ah,WRITE
inc bx ; To STDOUT (file 1)
int 21h
jmp read ; Go get more
done: ret
section .bss
buffer: resb BUFSZ