8086 machine code + DOS, 61 bytes
Hexdump (with ASCII view on the right):
B8 1E 01 8B F8 CD 21 B1 1F F2 AE 8B F7 AC 8A D0 ......!.........
B4 02 CD 21 80 E2 20 74 02 CD 21 E2 F0 C3 71 77 ...!.. t..!...qw
65 72 74 79 75 69 6F 70 0D 0A 61 73 64 66 67 68 ertyuiop..asdfgh
6A 6B 6C 0D 0A 7A 78 63 76 62 6E 6D 0D jkl..zxcvbnm.
Assembly source code (can be assembled with tasm):
.MODEL TINY
.CODE
org 100h
MAIN PROC
mov ax, offset qwerty ; sets ah=1 (coincidence)
mov di, ax ; di points to the string
int 21h ; reads a char from keyboard into al
mov cl, 31 ; cx is the length of the string
repne scasb ; look for the char
mov si, di ; si now points beyond the found char
myloop:
lodsb ; load a char
mov dl, al
mov ah, 2
int 21h ; output the char
and dl, 20h ; if it's a letter, set it to a space
jz print_done ; if it's not a letter, don't print a space
int 21h ; if it's a letter, print a space
print_done:
loop myloop ; repeat until end of string
ret
qwerty db 'qwertyuiop',13,10,'asdfghjkl',13,10,'zxcvbnm',13
MAIN ENDP
END MAIN
Two fun things here:
- The offset of the
qwerty
string is 0x011e
. The upper byte of it is 1, which is the DOS function number for character input. This saves 1 byte in the code.
- All lower-case letters have bit 5 set. When doing an
AND
with 0x20
, they are all turned into a space, which is then printed. If the previous char was an end-of-line byte, it gets turned into 0, and no space is output. This is used to avoid the nonsensical sequence 0d 20 0a 20
at end of line.
One almost-fun thing:
I tried to search for the input char starting at address 0 (that decreased program size by 2 bytes), instead of the usual place (start of the string). This almost worked; however, it failed for input t
, because the code itself contains the byte t
(as part of the encoding of a conditional jump). So for t
, it would output a few junk bytes: