Skip to main content
Commonmark migration
Source Link

#8088 machine code, IBM PC DOS, 35 bytes

8088 machine code, IBM PC DOS, 35 bytes

#8088 machine code, IBM PC DOS, 35 bytes

8088 machine code, IBM PC DOS, 35 bytes

Program length no longer hard-coded
Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57
B1 23       MOV  CL, 23H        ; program is 35 bytes, display 70 chars 
        _LOOP:     
AC          LODSB               ; load byte [SI] into AL, increment SI 
8A F0       MOV  DH, AL         ; save original byte in DH 
51          PUSH CX             ; save outer loop counter 
B9 0204     MOV  CX, 0204H      ; set up nibble counter and shift count 
D2 C0       ROL  AL, CL         ; reverse nibbles (display high order first) 
        _NIB:      
24 0F       AND  AL, 0FH        ; mask low nibble 
3C 0A       CMP  AL, 0AH        ; is < 10? 
72 02       JC   _ASC           ; if so, is a numeric digit 
04 07       ADD  AL, 07H        ; otherwise adjust for A-F hex ASCII 
        _ASC: 
04 30       ADD  AL, '0'        ; ASCII convert 
B4 0E       MOV  AH, 0EH        ; BIOS output char function 
CD 10       INT  10H            ; display char 
8A C6       MOV  AL, DH         ; restore original nibble to AL 
FE CD       DEC  CH             ; decrement nibble counter 
75 EC       JNZ  _NIB           ; if > 0, repeat 
5981 FE 0123  CMP  SI, OFFSET _EF ; POPis SI CX< last byte? 
7C DE       JL   _LOOP          ; restoreif outerso, loopkeep counterlooping 
E2C3 E0       LOOP _LOOP RET         ; continue loop 
C3     ; return to DOS  
   RET     _EF EQU $               ; returnget toprogram DOSsize 

enter image description hereenter image description here

B1 23       MOV  CL, 23H        ; program is 35 bytes, display 70 chars 
        _LOOP:     
AC          LODSB               ; load byte [SI] into AL, increment SI 
8A F0       MOV  DH, AL         ; save original byte in DH 
51          PUSH CX             ; save outer loop counter 
B9 0204     MOV  CX, 0204H      ; set up nibble counter and shift count 
D2 C0       ROL  AL, CL         ; reverse nibbles (display high order first) 
        _NIB:      
24 0F       AND  AL, 0FH        ; mask low nibble 
3C 0A       CMP  AL, 0AH        ; is < 10? 
72 02       JC   _ASC           ; if so, is a numeric digit 
04 07       ADD  AL, 07H        ; otherwise adjust for A-F hex ASCII 
        _ASC: 
04 30       ADD  AL, '0'        ; ASCII convert 
B4 0E       MOV  AH, 0EH        ; BIOS output char function 
CD 10       INT  10H            ; display char 
8A C6       MOV  AL, DH         ; restore original nibble to AL 
FE CD       DEC  CH             ; decrement nibble counter 
75 EC       JNZ  _NIB           ; if > 0, repeat 
59          POP  CX             ; restore outer loop counter 
E2 E0       LOOP _LOOP          ; continue loop 
C3          RET                 ; return to DOS 

enter image description here

        _LOOP:     
AC          LODSB               ; load byte [SI] into AL, increment SI 
8A F0       MOV  DH, AL         ; save original byte in DH 
B9 0204     MOV  CX, 0204H      ; set up nibble counter and shift count 
D2 C0       ROL  AL, CL         ; reverse nibbles (display high order first) 
        _NIB:      
24 0F       AND  AL, 0FH        ; mask low nibble 
3C 0A       CMP  AL, 0AH        ; is < 10? 
72 02       JC   _ASC           ; if so, is a numeric digit 
04 07       ADD  AL, 07H        ; otherwise adjust for A-F hex ASCII 
        _ASC: 
04 30       ADD  AL, '0'        ; ASCII convert 
B4 0E       MOV  AH, 0EH        ; BIOS output char function 
CD 10       INT  10H            ; display char 
8A C6       MOV  AL, DH         ; restore original nibble to AL 
FE CD       DEC  CH             ; decrement nibble counter 
75 EC       JNZ  _NIB           ; if > 0, repeat 
81 FE 0123  CMP  SI, OFFSET _EF ; is SI < last byte? 
7C DE       JL   _LOOP          ; if so, keep looping 
C3          RET                 ; return to DOS  
        _EF EQU $               ; get program size 

enter image description here

Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57

#8088 machine code, IBM PC DOS, 35 bytes

Unassembled listing:

B1 23       MOV  CL, 23H        ; program is 35 bytes, display 70 chars 
        _LOOP:     
AC          LODSB               ; load byte [SI] into AL, increment SI 
8A F0       MOV  DH, AL         ; save original byte in DH 
51          PUSH CX             ; save outer loop counter 
B9 0204     MOV  CX, 0204H      ; set up nibble counter and shift count 
D2 C0       ROL  AL, CL         ; reverse nibbles (display high order first) 
        _NIB:      
24 0F       AND  AL, 0FH        ; mask low nibble 
3C 0A       CMP  AL, 0AH        ; is < 10? 
72 02       JC   _ASC           ; if so, is a numeric digit 
04 07       ADD  AL, 07H        ; otherwise adjust for A-F hex ASCII 
        _ASC: 
04 30       ADD  AL, '0'        ; ASCII convert 
B4 0E       MOV  AH, 0EH        ; BIOS output char function 
CD 10       INT  10H            ; display char 
8A C6       MOV  AL, DH         ; restore original nibble to AL 
FE CD       DEC  CH             ; decrement nibble counter 
75 EC       JNZ  _NIB           ; if > 0, repeat 
59          POP  CX             ; restore outer loop counter 
E2 E0       LOOP _LOOP          ; continue loop 
C3          RET                 ; return to DOS 

This is a complete IBM PC DOS executable that displays itself as ASCII hex, so will always output as twice the program size.

Output

enter image description here

Download and test SELF.COM!