Skip to main content
deleted 57 characters in body
Source Link
Endenite
  • 4.1k
  • 12
  • 28

z80 Machine Code, 13 bytes

47 1F 1F 1F A8 E6 01 05 10 01 3D C6 30

Takes input (starting at 1) in the A register and stores output in the same register. This was manually assembled from the ez80 manual and is not yet tested, therefore it might contain some mistakes.

Explanation:

47        ld b, a         ; Copy the value to the B register
1F 1F 1F  rra   (3 times) ; Rightrotate\ theSet A registerto 3((A times,>> moving3) bit^ 3B) to& bit1, 0which is
A8        xor a, b        ; Xor A and B into A, which sets bit 0 of| Aequal to 1 on all months with 31 days
E6 01     and a, 1        ; Set all other bits to/ zero
05        dec b           ; \ Decrement the B register twice and skip the next instruction if 
10 01     djnz $+3        ; Decrement B again and skip/ the nextresulting instructionvalue ifis not equal to zero (if the month is not february)
3D        dec a           ; Decrement A (if february)
C6 30     add a, 30       ; Add 30 to A

z80 Machine Code, 13 bytes

47 1F 1F 1F A8 E6 01 05 10 01 3D C6 30

Takes input (starting at 1) in the A register and stores output in the same register. This was manually assembled from the ez80 manual and is not yet tested, therefore it might contain some mistakes.

Explanation:

47        ld b, a         ; Copy the value to the B register
1F 1F 1F  rra   (3 times) ; Rightrotate the A register 3 times, moving bit 3 to bit 0
A8        xor a, b        ; Xor A and B into A, which sets bit 0 of A to 1 on all months with 31 days
E6 01     and a, 1        ; Set all other bits to zero
05        dec b           ; Decrement the B register
10 01     djnz $+3        ; Decrement B again and skip the next instruction if not equal to zero (if not february)
3D        dec a           ; Decrement A (if february)
C6 30     add a, 30       ; Add 30 to A

z80 Machine Code, 13 bytes

47 1F 1F 1F A8 E6 01 05 10 01 3D C6 30

Takes input (starting at 1) in the A register and stores output in the same register. This was manually assembled from the ez80 manual and is not yet tested, therefore it might contain some mistakes.

Explanation:

47        ld b, a         ; Copy the value to the B register
1F 1F 1F  rra   (3 times) ; \ Set A to ((A >> 3) ^ B) & 1, which is
A8        xor a, b        ; | equal to 1 on all months with 31 days
E6 01     and a, 1        ; / 
05        dec b           ; \ Decrement the B register twice and skip the next instruction if 
10 01     djnz $+3        ; / the resulting value is not zero (if the month is not february)
3D        dec a           ; Decrement A (if february)
C6 30     add a, 30       ; Add 30 to A
Source Link
Endenite
  • 4.1k
  • 12
  • 28

z80 Machine Code, 13 bytes

47 1F 1F 1F A8 E6 01 05 10 01 3D C6 30

Takes input (starting at 1) in the A register and stores output in the same register. This was manually assembled from the ez80 manual and is not yet tested, therefore it might contain some mistakes.

Explanation:

47        ld b, a         ; Copy the value to the B register
1F 1F 1F  rra   (3 times) ; Rightrotate the A register 3 times, moving bit 3 to bit 0
A8        xor a, b        ; Xor A and B into A, which sets bit 0 of A to 1 on all months with 31 days
E6 01     and a, 1        ; Set all other bits to zero
05        dec b           ; Decrement the B register
10 01     djnz $+3        ; Decrement B again and skip the next instruction if not equal to zero (if not february)
3D        dec a           ; Decrement A (if february)
C6 30     add a, 30       ; Add 30 to A