x86 machine code, 73 bytes
Inspired by Евгений Новиков's solution, I thought it should be doable with less tricks, i.e., just jumping around to otherwise "disjoint" codes for all three variants. I'm still trying with a smart variant that uses lodsb; lodsb
as central point (so only one string constant is needed for all variants)
EB 14 00 00 8A 8A 17 16 01 01 B4 B4 09 09 CD CD
21 21 CD CD 20 20 8A 1f 01 B4 09 CD 21 CD 20 48
65 6c 6c 6f 2c 20 57 6f 72 6c 64 21 00 48 48 65
65 6c 6c 6c 6c 6f 6f 2c 2c 20 20 57 57 6f 6f 72
72 6c 6c 64 64 21 21 00 00
If I recall correctly from my childhood days, COM's tiny model starts with DS=CS=SS
and the code is loaded beginning from CS:0100h
. I do not assume it is guaranteed that the code is loaded into a zeroed memory block (if it were guaranteed, I could drop two bytes).
Disassembly of the long code should be
JMP *+14h
; 20 irrelevant bytes
MOV DX,message
MOV AH,09h
INT 21h; print string pointed to by DS:DX
INT 20h; exit program
message:
DB "Hello, World!\0"
DB "HHeelllloo,, WWoorrlldd!!\0\0"
Disassembly of odd code
JMP *+00h
MOV DX,message
MOV AH,09h
INT 21h; print string pointed to by DS:DX
INT 20h; exit program
; some irrelevant bytes
message:
DB "Hello, World!\0"
Disassembly of even code:
ADC AL,00h
MOV DX,message
MOV AH,09h
INT 21h; print string pointed to by DS:DX
INT 20h; exit program
; some irrelevant bytes
message:
DB "Hello, World!\0"
6Why not just change the text from "Hello, World!" to something else? – Conor O'Brien – 2017-07-02T03:32:48.110
1I think that avoids loopholes enough and "Hello, World!" is canonical. – Leo Tenenbaum – 2017-07-02T03:35:03.510
24IMO it'd be nice to see a different string than "Hello, World!" once in a while (that's just my opinion) – Conor O'Brien – 2017-07-02T03:36:03.857
1Are whitespaces and newlines counted as characters? – officialaimm – 2017-07-02T03:58:10.143
1@officialaimm Yes. – Leo Tenenbaum – 2017-07-02T05:20:34.103
Odd/even keeper https://jsfiddle.net/d71x6ah7/6/
– Евгений Новиков – 2017-07-02T15:17:50.9636@ConorO'Brien With the pleasant side effect that very few languages will have built-ins for literally every other string. – Dennis – 2017-07-02T18:14:52.423
Why are builtins banned here but not on Part 1? – CalculatorFeline – 2017-07-05T16:57:01.703
Why exactly was this marked as a duplicate? – Leo Tenenbaum – 2017-08-07T07:13:22.127
Because many programming languages ignore leading whitespace, so an answer to the duplicate could be made an answer to this one by adding or removing a leading space. – pppery – 2017-08-07T15:31:45.910
1@ppperry I think you misunderstood something in the question. The original question was just the full program and the odd characters, but this one is the full program, the even characters, and the odd characters. This makes it much harder to find a solution. For example, in the original question, since many golfing languages ignore spaces, you could just do a regular hello world, but with spaces in between each letter. In part 2, this wouldn't work. – Leo Tenenbaum – 2017-08-07T15:49:52.140
Oh, I did. That wasn't very clear. – pppery – 2017-08-07T15:50:55.260
@ppperry Thanks for the feedback. I've clarified my question. – Leo Tenenbaum – 2017-08-07T15:59:24.980