Difference between revisions of "MELT.COM"

From SizeCoding
Jump to: navigation, search
Line 11: Line 11:
 
                 mov    es, ax          ; es now points to screen segment
 
                 mov    es, ax          ; es now points to screen segment
  
doScreen:                              ; CODE XREF: start+2B�j
+
doScreen:                               
 
                 mov    cx, 2000        ; Going to loop over all 2000 characters
 
                 mov    cx, 2000        ; Going to loop over all 2000 characters
 
                                         ; (80 * 25 = 2000)
 
                                         ; (80 * 25 = 2000)
Line 18: Line 18:
 
                 mov    di, bx          ; es:di now points at the screen (b800:0000)
 
                 mov    di, bx          ; es:di now points at the screen (b800:0000)
  
alterChars:                            ; CODE XREF: start+26�j
+
alterChars:                             
 
                 mov    ah, es:[di]    ; Retreive onscreen character
 
                 mov    ah, es:[di]    ; Retreive onscreen character
 
                 cmp    ah, 32          ; comp to a space character (#32)
 
                 cmp    ah, 32          ; comp to a space character (#32)
Line 29: Line 29:
 
; ---------------------------------------------------------------------------
 
; ---------------------------------------------------------------------------
  
upToSpace:                              ; CODE XREF: start+14�j
+
upToSpace:                               
 
                 inc    ah              ; Increase character upwards towards a space
 
                 inc    ah              ; Increase character upwards towards a space
 
                 mov    es:[di], ah    ; Store altered character back to screen
 
                 mov    es:[di], ah    ; Store altered character back to screen
 
                 inc    bx              ; increase "number of processed chars" counter
 
                 inc    bx              ; increase "number of processed chars" counter
  
nextChar:                              ; CODE XREF: start+12�j start+1C�j
+
nextChar:                               
 
                 inc    di
 
                 inc    di
 
                 inc    di              ; es:di now points to next character
 
                 inc    di              ; es:di now points to next character
Line 42: Line 42:
 
                 mov    ah, 4Ch        ; Otherwise, get ready to terminate
 
                 mov    ah, 4Ch        ; Otherwise, get ready to terminate
 
                 int    21h            ; DOS - 2+ - QUIT WITH EXIT CODE (EXIT)
 
                 int    21h            ; DOS - 2+ - QUIT WITH EXIT CODE (EXIT)
 
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 03:12, 7 August 2016

MELT.COM was written by an unknown author in the 1980s. Originally 49 bytes in size, it performs the following cute effect:

The original source is lost to history, but here's a quick commented disassembly:

                org 100h

                mov     ax, 0B800h
                mov     es, ax          ; es now points to screen segment

doScreen:                               
                mov     cx, 2000        ; Going to loop over all 2000 characters
                                        ; (80 * 25 = 2000)
                xor     bx, bx          ; bx = 0
                                        ; bx is also our "num of altered chars" counter
                mov     di, bx          ; es:di now points at the screen (b800:0000)

alterChars:                             
                mov     ah, es:[di]     ; Retreive onscreen character
                cmp     ah, 32          ; comp to a space character (#32)
                jz      short nextChar  ; If already a space, do nothing
                jl      short upToSpace ; If lower than a space, increase upward
                dec     ah              ; If higher than a space, decrease downward
                mov     es:[di], ah     ; Store altered character back to screen
                inc     bx              ; increase "number of processed chars" counter
                jmp     short nextChar  ; Keep processing characters
; ---------------------------------------------------------------------------

upToSpace:                              
                inc     ah              ; Increase character upwards towards a space
                mov     es:[di], ah     ; Store altered character back to screen
                inc     bx              ; increase "number of processed chars" counter

nextChar:                               
                inc     di
                inc     di              ; es:di now points to next character
                loop    alterChars      ; Continue processing characters
                cmp     bx, 0           ; Were any characters processed?
                jnz     short doScreen  ; If so (bx != 0), keep processing
                mov     ah, 4Ch         ; Otherwise, get ready to terminate
                int     21h             ; DOS - 2+ - QUIT WITH EXIT CODE (EXIT)