Skip to main content
Code shortening
Source Link
ErikF
  • 4.8k
  • 9
  • 11

x86 machine code (MS-DOS .COM format), 53 4949 44 bytes

Edit: Saved 4 bytes by eliminating a redundant CALL/RET and 5 bytes by outputting via INT 29H.

Input is taken from the command line: no input will search for NUL (hex 00H). Result is in the form "00/00" (i.e. "03/53"44" for an input of "!)").

A0 82 00 B9 312C 00 33 D2 BF 00 01 F2 AE E3 03 42 EB F9 8B C2 E8 07 00 B2B0 2F CD 2129 B8 312C 00 D4 0A 8B D0 81 C205 30 30 B4 02 86 F2E0 CD 2129 86 F2E0 CD 2129 C3
IDEAL

MODEL   TINY
CODESEG
ORG 100H

PSIZE   EQU PEND-MAIN
PLEN    EQU PSIZE+1     ; Loop needs to be one longerlarger so we can break aton CX=0

MAIN:
    MOV     AL,[0082H]  ; Get search value from the command line
    MOV     CX,PLEN
    XOR     DX,DX
    MOV     DI,100H     ; Start search from the beginning of the program
CLOOP:
    REPNZ   SCASB       ; Search for value
    JCXZ    CDONE       ; Exit when at of end of string
    INC     DX
    JMP     CLOOP
CDONE:
    MOV     AX,DX
    CALL    DISPNUM
    MOV DL    AL,'/'
    INT 21H    29H
    MOV     AX,PSIZE
    ; Fallthrough to print last number and exit

DISPNUM:
    AAM                 ; Convert value to unpacked BCD (AH:AL)
    MOV DX,AX
ADD    ADD DXAX,3030H ; 
 Convert to ASCII
 XCHG   MOV AH,2AL
    XCHGINT DH,DL ; Flip digits to29H
 prepare for printing
 XCHG   INT 21HAH,AL
    XCHG DH,DL
INT    INT 21H29H
    RET

PEND:

END MAIN
ENDS

x86 machine code (MS-DOS .COM format), 53 49 bytes

Input is taken from the command line: no input will search for NUL (hex 00H). Result is in the form "00/00" (i.e. "03/53" for an input of "!").

A0 82 00 B9 31 00 33 D2 BF 00 01 F2 AE E3 03 42 EB F9 8B C2 E8 07 00 B2 2F CD 21 B8 31 00 D4 0A 8B D0 81 C2 30 30 B4 02 86 F2 CD 21 86 F2 CD 21 C3
IDEAL

MODEL TINY
CODESEG
ORG 100H

PSIZE EQU PEND-MAIN
PLEN  EQU PSIZE+1 ; Loop needs to be one longer so we can break at CX=0

MAIN:
    MOV AL,[0082H] ; Get search value from the command line
    MOV CX,PLEN
    XOR DX,DX
    MOV DI,100H ; Start search from the beginning of the program
CLOOP:
    REPNZ SCASB ; Search for value
    JCXZ CDONE ; Exit when at of end of string
    INC DX
    JMP CLOOP
CDONE:
    MOV AX,DX
    CALL DISPNUM
    MOV DL,'/'
    INT 21H
    MOV AX,PSIZE
    ; Fallthrough to print last number and exit

DISPNUM:
    AAM ; Convert value to unpacked BCD (AH:AL)
    MOV DX,AX
    ADD DX,3030H ; Convert to ASCII
    MOV AH,2
    XCHG DH,DL ; Flip digits to prepare for printing
    INT 21H
    XCHG DH,DL
    INT 21H
    RET

PEND:

END MAIN
ENDS

x86 machine code (MS-DOS .COM format), 53 49 44 bytes

Edit: Saved 4 bytes by eliminating a redundant CALL/RET and 5 bytes by outputting via INT 29H.

Input is taken from the command line: no input will search for NUL (hex 00H). Result is in the form "00/00" (i.e. "03/44" for an input of ")").

A0 82 00 B9 2C 00 33 D2 BF 00 01 F2 AE E3 03 42 EB F9 8B C2 E8 07 00 B0 2F CD 29 B8 2C 00 D4 0A 05 30 30 86 E0 CD 29 86 E0 CD 29 C3
IDEAL

MODEL   TINY
CODESEG
ORG 100H

PSIZE   EQU PEND-MAIN
PLEN    EQU PSIZE+1     ; Loop needs to be one larger so we can break on CX=0

MAIN:
    MOV     AL,[0082H]  ; Get search value from the command line
    MOV     CX,PLEN
    XOR     DX,DX
    MOV     DI,100H     ; Start search from the beginning of the program
CLOOP:
    REPNZ   SCASB       ; Search for value
    JCXZ    CDONE       ; Exit when at end of string
    INC     DX
    JMP     CLOOP
CDONE:
    MOV     AX,DX
    CALL    DISPNUM
    MOV     AL,'/'
    INT     29H
    MOV     AX,PSIZE
    ; Fallthrough to print last number and exit

DISPNUM:
    AAM                 ; Convert value to unpacked BCD (AH:AL)
    ADD     AX,3030H 
    XCHG    AH,AL
    INT     29H
    XCHG    AH,AL
    INT     29H
    RET

PEND:

END MAIN
ENDS
Typo
Source Link
ErikF
  • 4.8k
  • 9
  • 11

x86 machine code (MS-DOS .COM format), 53 49 bytes

Input is taken from the command line: no input will search for NUL (hex 00H). Result is in the form "00/00" (i.e. "03/53" for an input of "!").

The counting part is really easy since this is a COM program: I scan for the target byte starting at DS:100H until I hit the end of the program code. To print the result and total counts, I use AAM to convert the numbers into unpacked BCD (which will always be less than 99) and then print the digits after flipping them so that they're displayed in the correct order.

Hex dump:

A0 82 00 B9 31 00 33 D2 BF 00 01 F2 AE E3 03 42 EB F9 8B C2 E8 07 00 B2 2F CD 21 B8 31 00 D4 0A 8B D0 81 C2 30 30 B4 02 86 F2 CD 21 86 F2 CD 21 C3

TASM source for generated code:

IDEAL

MODEL TINY
CODESEG
ORG 100H

PSIZE EQU PEND-MAIN
PLEN  EQU PLEN+1PSIZE+1 ; Loop needs to be one longer so we can break at CX=0

MAIN:
    MOV AL,[0082H] ; Get search value from the command line
    MOV CX,PLEN
    XOR DX,DX
    MOV DI,100H ; Start search from the beginning of the program
CLOOP:
    REPNZ SCASB ; Search for value
    JCXZ CDONE ; Exit when at of end of string
    INC DX
    JMP CLOOP
CDONE:
    MOV AX,DX
    CALL DISPNUM
    MOV DL,'/'
    INT 21H
    MOV AX,PSIZE
    ; Fallthrough to print last number and exit

DISPNUM:
    AAM ; Convert value to unpacked BCD (AH:AL)
    MOV DX,AX
    ADD DX,3030H ; Convert to ASCII
    MOV AH,2
    XCHG DH,DL ; Flip digits to prepare for printing
    INT 21H
    XCHG DH,DL
    INT 21H
    RET

PEND:

END MAIN
ENDS

x86 machine code (MS-DOS .COM format), 53 49 bytes

Input is taken from the command line: no input will search for NUL (hex 00H). Result is in the form "00/00" (i.e. "03/53" for an input of "!").

The counting part is really easy since this is a COM program: I scan for the target byte starting at DS:100H until I hit the end of the program code. To print the result and total counts, I use AAM to convert the numbers into unpacked BCD (which will always be less than 99) and then print the digits after flipping them so that they're displayed in the correct order.

Hex dump:

A0 82 00 B9 31 00 33 D2 BF 00 01 F2 AE E3 03 42 EB F9 8B C2 E8 07 00 B2 2F CD 21 B8 31 00 D4 0A 8B D0 81 C2 30 30 B4 02 86 F2 CD 21 86 F2 CD 21 C3

TASM source for generated code:

IDEAL

MODEL TINY
CODESEG
ORG 100H

PSIZE EQU PEND-MAIN
PLEN  EQU PLEN+1 ; Loop needs to be one longer so we can break at CX=0

MAIN:
    MOV AL,[0082H] ; Get search value from the command line
    MOV CX,PLEN
    XOR DX,DX
    MOV DI,100H ; Start search from the beginning of the program
CLOOP:
    REPNZ SCASB ; Search for value
    JCXZ CDONE ; Exit when at of end of string
    INC DX
    JMP CLOOP
CDONE:
    MOV AX,DX
    CALL DISPNUM
    MOV DL,'/'
    INT 21H
    MOV AX,PSIZE
    ; Fallthrough to print last number and exit

DISPNUM:
    AAM ; Convert value to unpacked BCD (AH:AL)
    MOV DX,AX
    ADD DX,3030H ; Convert to ASCII
    MOV AH,2
    XCHG DH,DL ; Flip digits to prepare for printing
    INT 21H
    XCHG DH,DL
    INT 21H
    RET

PEND:

END MAIN
ENDS

x86 machine code (MS-DOS .COM format), 53 49 bytes

Input is taken from the command line: no input will search for NUL (hex 00H). Result is in the form "00/00" (i.e. "03/53" for an input of "!").

The counting part is really easy since this is a COM program: I scan for the target byte starting at DS:100H until I hit the end of the program code. To print the result and total counts, I use AAM to convert the numbers into unpacked BCD (which will always be less than 99) and then print the digits after flipping them so that they're displayed in the correct order.

Hex dump:

A0 82 00 B9 31 00 33 D2 BF 00 01 F2 AE E3 03 42 EB F9 8B C2 E8 07 00 B2 2F CD 21 B8 31 00 D4 0A 8B D0 81 C2 30 30 B4 02 86 F2 CD 21 86 F2 CD 21 C3

TASM source for generated code:

IDEAL

MODEL TINY
CODESEG
ORG 100H

PSIZE EQU PEND-MAIN
PLEN  EQU PSIZE+1 ; Loop needs to be one longer so we can break at CX=0

MAIN:
    MOV AL,[0082H] ; Get search value from the command line
    MOV CX,PLEN
    XOR DX,DX
    MOV DI,100H ; Start search from the beginning of the program
CLOOP:
    REPNZ SCASB ; Search for value
    JCXZ CDONE ; Exit when at of end of string
    INC DX
    JMP CLOOP
CDONE:
    MOV AX,DX
    CALL DISPNUM
    MOV DL,'/'
    INT 21H
    MOV AX,PSIZE
    ; Fallthrough to print last number and exit

DISPNUM:
    AAM ; Convert value to unpacked BCD (AH:AL)
    MOV DX,AX
    ADD DX,3030H ; Convert to ASCII
    MOV AH,2
    XCHG DH,DL ; Flip digits to prepare for printing
    INT 21H
    XCHG DH,DL
    INT 21H
    RET

PEND:

END MAIN
ENDS
Code correction (fencepost error)
Source Link
ErikF
  • 4.8k
  • 9
  • 11

x86 machine code (MS-DOS .COM format), 53 49 bytes

Input is taken from the command line: no input will search for NUL (hex 00H). Result is in the form "00/00" (i.e. "03/53" for an input of "!").

The counting part is really easy since this is a COM program: I scan for the target byte starting at DS:100H until I hit the end of the program code. To print the result and total counts, I use AAM to convert the numbers into unpacked BCD (which will always be less than 99) and then print the digits after flipping them so that they're displayed in the correct order.

Hex dump:

A0 82 00 B9 31 00 33 D2 BF 00 01 F2 AE E3 03 42 EB F9 8B C2 E8 07 00 B2 2F CD 21 B8 31 00 D4 0A 8B D0 81 C2 30 30 B4 02 86 F2 CD 21 86 F2 CD 21 C3

TASM source for generated code:

IDEAL
P186

MODEL TINY
CODESEG
ORG 100H

PSIZE EQU PEND-MAIN
PLEN  EQU PLEN+1 ; Loop needs to be one longer so we can break at CX=0

MAIN:
    MOV AL,[0082H] ; Get search value from the command line
    MOV CX,PSIZEPLEN
    XOR DX,DX
    MOV DI,100H ; Start search from the beginning of the program
CLOOP:
    REPNZ SCASB ; Search for value
    JCXZ CDONE ; Exit when at of end of string
    INC DX
    JMP CLOOP
CDONE:
    MOV AX,DX
    CALL DISPNUM
    MOV DL,'/'
    INT 21H
    MOV AX,PSIZE
    ; Fallthrough to print last number and exit

DISPNUM:
    AAM ; Convert value to unpacked BCD (AH:AL)
    MOV DX,AX
    ADD DX,3030H ; Convert to ASCII
    MOV AH,2
    XCHG DH,DL ; Flip digits to prepare for printing
    INT 21H
    XCHG DH,DL
    INT 21H
    RET

PEND:

END MAIN
ENDS

x86 machine code (MS-DOS .COM format), 53 49 bytes

Input is taken from the command line: no input will search for NUL (hex 00H). Result is in the form "00/00" (i.e. "03/53" for an input of "!").

The counting part is really easy since this is a COM program: I scan for the target byte starting at DS:100H until I hit the end of the program code. To print the result and total counts, I use AAM to convert the numbers into unpacked BCD (which will always be less than 99) and then print the digits after flipping them so that they're displayed in the correct order.

Hex dump:

A0 82 00 B9 31 00 33 D2 BF 00 01 F2 AE E3 03 42 EB F9 8B C2 E8 07 00 B2 2F CD 21 B8 31 00 D4 0A 8B D0 81 C2 30 30 B4 02 86 F2 CD 21 86 F2 CD 21 C3

TASM source for generated code:

IDEAL
P186

MODEL TINY
CODESEG
ORG 100H

PSIZE EQU PEND-MAIN

MAIN:
    MOV AL,[0082H] ; Get search value from the command line
    MOV CX,PSIZE
    XOR DX,DX
    MOV DI,100H ; Start search from the beginning of the program
CLOOP:
    REPNZ SCASB ; Search for value
    JCXZ CDONE ; Exit when at of end of string
    INC DX
    JMP CLOOP
CDONE:
    MOV AX,DX
    CALL DISPNUM
    MOV DL,'/'
    INT 21H
    MOV AX,PSIZE
    ; Fallthrough to print last number and exit

DISPNUM:
    AAM ; Convert value to unpacked BCD (AH:AL)
    MOV DX,AX
    ADD DX,3030H ; Convert to ASCII
    MOV AH,2
    XCHG DH,DL ; Flip digits to prepare for printing
    INT 21H
    XCHG DH,DL
    INT 21H
    RET

PEND:

END MAIN
ENDS

x86 machine code (MS-DOS .COM format), 53 49 bytes

Input is taken from the command line: no input will search for NUL (hex 00H). Result is in the form "00/00" (i.e. "03/53" for an input of "!").

The counting part is really easy since this is a COM program: I scan for the target byte starting at DS:100H until I hit the end of the program code. To print the result and total counts, I use AAM to convert the numbers into unpacked BCD (which will always be less than 99) and then print the digits after flipping them so that they're displayed in the correct order.

Hex dump:

A0 82 00 B9 31 00 33 D2 BF 00 01 F2 AE E3 03 42 EB F9 8B C2 E8 07 00 B2 2F CD 21 B8 31 00 D4 0A 8B D0 81 C2 30 30 B4 02 86 F2 CD 21 86 F2 CD 21 C3

TASM source for generated code:

IDEAL

MODEL TINY
CODESEG
ORG 100H

PSIZE EQU PEND-MAIN
PLEN  EQU PLEN+1 ; Loop needs to be one longer so we can break at CX=0

MAIN:
    MOV AL,[0082H] ; Get search value from the command line
    MOV CX,PLEN
    XOR DX,DX
    MOV DI,100H ; Start search from the beginning of the program
CLOOP:
    REPNZ SCASB ; Search for value
    JCXZ CDONE ; Exit when at of end of string
    INC DX
    JMP CLOOP
CDONE:
    MOV AX,DX
    CALL DISPNUM
    MOV DL,'/'
    INT 21H
    MOV AX,PSIZE
    ; Fallthrough to print last number and exit

DISPNUM:
    AAM ; Convert value to unpacked BCD (AH:AL)
    MOV DX,AX
    ADD DX,3030H ; Convert to ASCII
    MOV AH,2
    XCHG DH,DL ; Flip digits to prepare for printing
    INT 21H
    XCHG DH,DL
    INT 21H
    RET

PEND:

END MAIN
ENDS
Code shortening
Source Link
ErikF
  • 4.8k
  • 9
  • 11
Loading
Source Link
ErikF
  • 4.8k
  • 9
  • 11
Loading