x86机器码 9 7字节
D1 E9 SHR CX, 1 ; divide length in half
AD LODSW ; load next two chars into AH/AL
3A E0 CMP AH, AL ; compare AH and AL
E1 FB LOOPE -5 ; if equal, continue loop
输入字符串in SI
,输入字符串长度in CX
。ZF
如果说两次,则输出。
或14个字节作为完整的PC DOS可执行文件:
B4 01 MOV AH, 01H ; DOS read char from STDIN (with echo)
CD 21 INT 21H ; read first char into AL
92 XCHG DX, AX ; put first char into DL
B4 08 MOV AH, 08H ; DOS read char from STDIN (no echo)
CD 21 INT 21H ; read second char into AL
3A C2 CMP AL, DL ; compare first and second char
74 F3 JE -13 ; if the same, continue loop
C3 RET ; otherwise exit to DOS
通过STDIN
管道或交互式输入。将回显“已加倍”的输入,直到检测到未加倍的字符为止,这时将退出(也许弯曲一点I / O规则,但这只是一个额外的答案)。
使用xxd -r
以下命令构建和测试ISDBL2.COM :
00000000: b401 cd21 92b4 08cd 213a c274 f3c3 ...!....!:.t..
原始的24个字节的完整PC DOS可执行文件:
D1 EE SHR SI, 1 ; SI to DOS PSP (080H)
AD LODSW ; load string length into AL
D0 E8 SHR AL, 1 ; divide length in half
8A C8 MOV CL, AL ; put string length into BL
CLOOP:
AD LODSW ; load next two chars into AH/AL
3A E0 CMP AH, AL ; compare AH and AL
E1 FB LOOPE CLOOP ; if equal, continue loop
DONE:
B8 0E59 MOV AX, 0E59H ; BIOS tty function in AH, 'Y' in AL
74 02 JZ DISP ; if ZF, result was valid double
B0 4E MOV AL, 'N' ; if not, change output char to N
DISP:
B4 0E MOV AH, 0EH
CD 10 INT 10H
C3 RET ; return to DOS
从命令行输入'Y'
,'N'
如果不是,则输出到屏幕。
使用xxd -r
以下命令构建和测试ISDBL.COM :
00000000: d1ee add0 e88a c8ad 3ae0 e1fb b859 0e74 ........:....Y.t
00000010: 02b0 4eb4 0ecd 10c3 ..N.....
学分: