Difference between revisions of "MELT.COM"

From SizeCoding
Jump to: navigation, search
Line 6: Line 6:
  
 
<syntaxhighlight lang=nasm>
 
<syntaxhighlight lang=nasm>
;narf
+
                org 100h
 +
 
 +
                mov    ax, 0B800h
 +
                mov    es, ax          ; es now points to screen segment
 +
 
 +
doScreen:                              ; CODE XREF: start+2B�j
 +
                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:                            ; CODE XREF: start+26�j
 +
                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:                              ; CODE XREF: start+14�j
 +
                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:                              ; CODE XREF: start+12�j start+1C�j
 +
                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)
 +
 
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 02: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:                               ; CODE XREF: start+2B�j
                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:                             ; CODE XREF: start+26�j
                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:                              ; CODE XREF: start+14�j
                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:                               ; CODE XREF: start+12�j start+1C�j
                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)