x86-16 machine code, 61 55 54 bytes
00000000: be82 008b fe8b d6ad 86c4 9346 56ad 86c4 ...........FV...
00000010: 4037 0430 3d30 367c 1293 4037 0430 3d34 @7.0=06|[email protected]=4
00000020: 327c 03b8 3030 86c4 abb0 305f 86c4 abb8 2|..00....0_....
00000030: 2409 aacd 21c3 $...!.
Listing:
BE 0082 MOV SI, 82H ; SI point to DOS command line tail
8B FE MOV DI, SI ; save pointer to beginning of string for later
8B D6 MOV DX, SI ; save pointer to beginning of string for output
AD LODSW ; load hours digits into AX
86 C4 XCHG AL, AH ; endian convert
93 XCHG AX, BX ; save hours in BX
46 INC SI ; skip colon
56 PUSH SI ; save string offset to minutes
AD LODSW ; load minutes digits into AX
86 C4 XCHG AL, AH ; endian convert
40 INC AX ; add one minute
37 AAA ; BCD Adjust After Addition!
04 30 ADD AL, '0' ; ASCII fix low digit
3D 3630 CMP AX, '60' ; is minutes wrap around?
7C 13 JL NO_CARRY_HOUR ; if not, skip hours
93 XCHG AX, BX ; move hours into AX
40 INC AX ; increment hours
37 AAA ; BCD Adjust After Addition!
04 30 ADD AL, '0' ; ASCII fix low digit
3D 3234 CMP AX, '24' ; rolled over to 24 hours?
7C 03 JL NO_CARRY_DAY ; if not, skip to convert
B8 3030 MOV AX, '00' ; reset hours to '00'
NO_CARRY_DAY:
86 C4 XCHG AL, AH ; endian convert
AB STOSW ; write hours string
B0 30 MOV AL, '0' ; reset minutes to '00'
NO_CARRY_HOUR:
5F POP DI ; minutes string offset to DI
86 C4 XCHG AL, AH ; endian convert
AB STOSW ; write minutes to output string
B8 0924 MOV AX, 0924H ; AL = '$', AH = write string function
AA STOSB ; write DOS string terminator to end of string
CD 21 INT 21H ; write output to console
C3 RET ; return to DOS
Thought it would be a more straightforward use of BCD operations, though it gave me a use for the AAA
instruction so there's that.
Standalone DOS executable. Input via command line, output to console.
OR...
21 bytes if I could take I/O as a packed BCD hex word (12:59
== 0x1259
), and get to use AAA
's bastard step-sibling DAA
!
40 INC AX ; increment the time
27 DAA ; decimal adjust packed BCD
3C 60 CMP AL, 60H ; did minutes reach 60?
7C 0E JL DONE ; if not, do nothing else
32 C0 XOR AL, AL ; otherwise, reset minutes to 0
86 E0 XCHG AH, AL ; swap hours and minutes in AL
40 INC AX ; increment the hours
27 DAA ; decimal adjust packed BCD
3C 24 CMP AL, 24H ; did hours reach 24?
86 E0 XCHG AH, AL ; real quick, swap hours and minutes back
7C 02 JL DONE ; if less than 24, do nothing else
32 E4 XOR AH, AH ; otherwise, reset hour to 0
DONE:
C3 RET