section .bss
buffer resb 1
section .text
global _start
_start:
call ReadChar
cmp al, '4'
jne wait_enter
; we've got '4'
call ReadChar
cmp al, '2'
jne not_42
; we've got '42'
mov eax, 1
xor ebx, ebx
int 80h
not_42: ; we've got '4x'
mov dl, al
mov al, '4'
call PrintChar
mov al, dl
jmp wait_middle
wait_enter: ; nothing there, waiting for '\n'
call PrintChar
wait_loop:
call ReadChar
wait_middle:
call PrintChar
cmp al, 10
je _start
jmp wait_loop
;------- ReadChar --------------------
; reads one character from stdin into AL
ReadChar:
push edx
mov eax, 3
xor ebx, ebx
mov ecx, buffer
mov edx, 1
int 80h
mov al, [ecx]
pop edx
ret
;------ PrintChar ------------------
; prints character from AL to stdout
PrintChar:
push eax
push edx
mov [buffer], al
mov eax, 4
mov ebx, 1
mov ecx, buffer
mov edx, ebx
int 80h
pop edx
pop eax
ret