Highlight

2014-06-12

Learn how to program in Assembly code in 2 minutes using debug!

A computer is a calculator with more features and commands to use them.

To program it (tell it what to do) at the lowest human-readable level (one step above the zeroes and ones of binary), you can use Assembly code, as shown here:




A neater, yet perhaps slightly more complex version of "Hello World" in Assembly can be found here. Annotated version:
A                  ; enter assembly mode
MOV AH,9           ; set High byte of Accumulator register to display a string of text terminated by the '$' character
MOV DX,108         ; set Data register to the location of the string to display
INT 21             ; execute an I/O function set in AH register
RET                ; return
DB 'HELLO WORLD$'  ; store a string

R CX               ; set Counter register (switches from 16-bit mode to 32-bit mode on a 80386 CPU or better)
14                 ; current code position in hexadecimal to specify program length (14 is 20 in decimal)
N MYHELLO.COM      ; name your command file
W                  ; write the program to the file
Q                  ; quit debug
Sadly, Windows 2003 was the last OS that shipped with the debug command. There are other assemblers and operating systems that are free and actively supported. This tutorial site appears to focus on the NASM assembler on Linux.

Simple assembly code runs very fast (640x200 video on a 4.77MHz 8088 IBM PC Model 5150 with 640K RAM, SoundBlaster, and 20 MB HDD), but takes a lot of work to write, and each system tends to have different opcodes, so programmers in the 1970s invented and largely moved to more abstract, higher level languages like C. In the 1990s, another such step occurred, to Java, the most business-like among new '90s languages. Lately, though, since the 2000s, high-level scripting languages like Python have become more popular among people tired of typing a lot, for code that may run milliseconds slower, depending on flavor. Remember: First get it right, then make it fast.

1 comment:

  1. Also interesting/frightening: https://www.youtube.com/watch?v=g9_FYRAfyqQ

    ReplyDelete