Skip to main content
Commonmark migration
Source Link

#Z80 Machine Code, 8 6 bytes*

Z80 Machine Code, 8 6 bytes*

#Z80 Machine Code, 30 bytes

Z80 Machine Code, 30 bytes

#Z80 Machine Code, 8 6 bytes*

#Z80 Machine Code, 30 bytes

Z80 Machine Code, 8 6 bytes*

Z80 Machine Code, 30 bytes

Golfed!
Source Link
CJ Dennis
  • 4.3k
  • 1
  • 16
  • 34

#Z80 Machine Code, 88 6 bytes*

ww8><8ww<8ww8> * Assumes certain conditions by entering from Amstrad BASIC

w   LD (HL), A    ## Saves A (0) to random memory location in (HL)
w   LD (HL), A    ## Saves A (0) to the same random memory location in (HL)
8>  JR C, #3E     ## C is initially unset, does nothing
<   INC A         // A=A+1
8w  JR C, #77     ## C is unset unless A has overflowed, does nothing 

w   LD (HL), A    // Saves A to the same random memory location in (HL (randomly initialised)
8>  JR C, #3E     ## C is still unset, does nothing

A is initially 0 when entered from BASIC. It increments A n times, then writes it n times to the same memory location (which is set to a slightly random location by BASIC)! The JR Jump Relative operation never does anything since the C flag is always unset, so is used to "comment out" the following byte! This version is slightly cheating by assuming certain entry conditions, namely entering from BASIC guarantees that A is always 0 and the C flag is unset. The location of (HL) is not guaranteed to be safe, and in fact, is probably a dangerous location. The below code is much more robust which is why it's so much longer.

#Z80 Machine Code, 8 bytes*

ww8><8ww * Assumes certain conditions by entering from Amstrad BASIC

w   LD (HL), A    ## Saves A (0) to random memory location in (HL)
w   LD (HL), A    ## Saves A (0) to the same random memory location in (HL)
8>  JR C, #3E     ## C is initially unset, does nothing
<   INC A         // A=A+1
8w  JR C, #77     ## C is unset unless A has overflowed, does nothing
w   LD (HL), A    // Saves A to the same random memory location in (HL)

This version is slightly cheating by assuming certain entry conditions, namely entering from BASIC guarantees that A is always 0 and the C flag is unset. The location of (HL) is not guaranteed to be safe, and in fact, is probably a dangerous location. The below code is much more robust which is why it's so much longer.

#Z80 Machine Code, 8 6 bytes*

<8ww8> * Assumes certain conditions by entering from Amstrad BASIC

<   INC A         // A=A+1
8w  JR C, #77     ## C is unset unless A has overflowed, does nothing 

w   LD (HL), A    // Saves A to memory location in HL (randomly initialised)
8>  JR C, #3E     ## C is still unset, does nothing

A is initially 0 when entered from BASIC. It increments A n times, then writes it n times to the same memory location (which is set to a slightly random location by BASIC)! The JR Jump Relative operation never does anything since the C flag is always unset, so is used to "comment out" the following byte! This version is slightly cheating by assuming certain entry conditions, namely entering from BASIC guarantees that A is always 0. The location of (HL) is not guaranteed to be safe, and in fact, is probably a dangerous location. The below code is much more robust which is why it's so much longer.

Rollback to Revision 4
Source Link
CJ Dennis
  • 4.3k
  • 1
  • 16
  • 34

#Z80 Machine Code, 8 68 bytes*

I<ww>Iww8><8ww * Assumes certain conditions by entering from Amstrad BASIC

Iw   LD C(HL), CA    ## Saves A (0) to random memory location in (HL)
w   LD (HL), A    ## LoadsSaves A (0) to the same random memory location in (HL)
8>  JR C, with#3E itself. Shortest safe instruction that## C is initially unset, does nothing!
<   INC A         // A=A+1
w 8w  LDJR (HL)C, A#77    // Saves## AC tois theunset memoryunless locationA inhas HL
overflowed, does nothing
w   LD (HL), A    // Saves A to the same random memory location in (HL
>I  LD A, #49     ## Loads A with #49 just before finishing!)

This version is slightly cheating by assuming certain entry conditions, namely entering from BASIC guarantees that A is always 0 and the C flag is unset. The location of (HL) is not guaranteed to be safe, and in fact, is probably a dangerous location. The below code is much more robust which is why it's so much longer.

#Z80 Machine Code, 8 6 bytes*

I<ww>I * Assumes certain conditions by entering from Amstrad BASIC

I   LD C, C       ## Loads C with itself. Shortest safe instruction that does nothing!
<   INC A         // A=A+1
w   LD (HL), A    // Saves A to the memory location in HL

w   LD (HL), A    // Saves A to the memory location in HL
>I  LD A, #49     ## Loads A with #49 just before finishing!

This version is slightly cheating by assuming certain entry conditions, namely entering from BASIC guarantees that A is always 0. The location of (HL) is not guaranteed to be safe, and in fact, is probably a dangerous location. The below code is much more robust which is why it's so much longer.

#Z80 Machine Code, 8 bytes*

ww8><8ww * Assumes certain conditions by entering from Amstrad BASIC

w   LD (HL), A    ## Saves A (0) to random memory location in (HL)
w   LD (HL), A    ## Saves A (0) to the same random memory location in (HL)
8>  JR C, #3E     ## C is initially unset, does nothing
<   INC A         // A=A+1
8w  JR C, #77     ## C is unset unless A has overflowed, does nothing
w   LD (HL), A    // Saves A to the same random memory location in (HL)

This version is slightly cheating by assuming certain entry conditions, namely entering from BASIC guarantees that A is always 0 and the C flag is unset. The location of (HL) is not guaranteed to be safe, and in fact, is probably a dangerous location. The below code is much more robust which is why it's so much longer.

Golfed
Source Link
CJ Dennis
  • 4.3k
  • 1
  • 16
  • 34
Loading
Shorter, unsafe version
Source Link
CJ Dennis
  • 4.3k
  • 1
  • 16
  • 34
Loading
Code table
Source Link
CJ Dennis
  • 4.3k
  • 1
  • 16
  • 34
Loading
Minor formatting
Source Link
CJ Dennis
  • 4.3k
  • 1
  • 16
  • 34
Loading
Source Link
CJ Dennis
  • 4.3k
  • 1
  • 16
  • 34
Loading