cpu 8086 org 256 start: mov dx, message mov cx, message_length call display mov dx, linebreak mov cx, linebreak_length call display mov si, message chunkloop: mov dx, si ; initialise offset of most recent chunk start byteloop: mov al, byte [si] ; get this byte cmp al, 'E' ; check for replacement je big ; replace big letter --> cmp al, 'e' je small ; replace small letter --> cmp al, 0 ; terminator ? je end ; yes, end --> inc si ; -> next byte jmp byteloop ; loop back to scan next byte big: call displaychunk ; display chunk up to this mov dx, replace_big mov cx, replace_big_length call display ; display replacement inc si ; -> next byte after what we replaced jmp chunkloop ; jump back and re-initialise dx so it will ; get the start offset of the next chunk small: ; (same code as for big, different replacement) call displaychunk mov dx, replace_small mov cx, replace_small_length call display inc si jmp chunkloop end: call displaychunk ; display the last chunk mov dx, linebreak mov cx, linebreak_length call display mov ax, 4C00h int 21h ; INP: ds:dx -> most recent chunk ; ds:si -> byte to be replaced (or terminator) ; REM: Here si points to behind the last byte that we ; want to write to display the chunk. Therefore ; si minus dx is the length we want to write. ; The chunk length may be zero (dx equals si). displaychunk: mov cx, si ; get offset behind the chunk sub cx, dx ; calculate length of chunk jz emptychunk ; if empty --> ; INP: ds:dx -> message data ; cx = length of message to write display: mov bx, 1 ; = stdout handle mov ah, 40h int 21h ; write to file handle emptychunk: retn message: db "In english: English" message_length equ $ - message db 0 ; terminator for main loop replace_big: db "Egg" replace_big_length equ $ - replace_big replace_small: db "egg" replace_small_length equ $ - replace_small linebreak: db 13,10 linebreak_length equ $ - linebreak