{"id":3448,"date":"2012-10-12T00:01:51","date_gmt":"2012-10-12T07:01:51","guid":{"rendered":"http:\/\/www.wambooli.com\/blog\/?p=3448"},"modified":"2012-10-12T14:38:34","modified_gmt":"2012-10-12T21:38:34","slug":"i-remember-assembly-language-part-ii","status":"publish","type":"post","link":"https:\/\/www.wambooli.com\/blog\/?p=3448","title":{"rendered":"I Remember Assembly Language, Part II"},"content":{"rendered":"<p>Assembly language runs fast. Assembly language produces small programs. But Assembly language takes nearly forever to write. That&#8217;s because you pretty much have to do everything from scratch.<br \/>\n<!--more--><br \/>\nUnlike higher-level programming languages &#8212; even the C language &#8212; Assembly has no libraries. There are some routines you can access in the computer&#8217;s ROM or in the operating system, but beyond that you have to code everything. That includes input, output, math &#8212; you name it. It&#8217;s a lot of work.<\/p>\n<p>The payoff, of course, is that the code runs super fast, especially when compared with the typical BASIC program of the era.<\/p>\n<p>As an example, here is code I wrote in 1988 that displays a message on the screen:<\/p>\n<pre><code>        DOSSEG\r\n        .MODEL small\r\n        .STACK 100h\r\n        .DATA\r\nmessage db      \"This is an .EXE file.$\"\r\n\r\n        .CODE\r\nstart:  mov ax,DGROUP\r\n        mov ds,ax\r\n        mov ah,9\r\n        mov dx,offset message\r\n        int 21h\r\n\r\n        mov ah,4Ch              ;leave\r\n        mov al,0                ;zero code\r\n        int 21h\r\n\r\n        END     start<\/code><\/pre>\n<p>The resulting executable file is only 244 bytes long. That size cannot be equalled by any other programming language. Granted, it&#8217;s entirely unreadable. Even if I wrote all the necessary comments, few non-Assembly programmers would understand the code itself. But as you can see from my comments above, I probably felt comfortable enough with what I was doing not to write comments.<\/p>\n<p>Generally speaking, most programs do more than display a single line of text. And yet, in Assembly, every little bit of the program must be coded.<\/p>\n<p>Below is a snipped from code I wrote. It takes a string of text stored in memory and converts that text into a value. The value is stored in one of the processor&#8217;s registers:<\/p>\n<pre><code>;---------------------------------------;\r\n;  Calculate string si==> into bx       ;\r\n;---------------------------------------;\r\nDECBIN  proc near\r\n        mov bx,0                        ;zero out initial value\r\nDget_next:\r\n        mov al,byte ptr [si]            ;read value\r\n        sub al,30h                      ;make binary\r\n        cbw                             ;make into a word\r\n        add bx,bx                       ;multiply bx by 10\r\n        push bx                         ;save *2\r\n        add bx,bx                       ;*4\r\n        add bx,bx                       ;*8\r\n        pop dx                          ;get back *2\r\n        add bx,dx                       ;*8 + *2 = *10\r\n        add bx,ax                       ;add new value\r\n        inc si                          ;bump pointer\r\n        cmp byte ptr [si],'0'           ;end of string?\r\n        jl Dleave                       ;go if so\r\n        cmp byte ptr [si],'9'           ;other possible end\r\n        jle Dget_next                   ;if not, continue\r\nDleave:\r\n        ret\r\nDECBIN  endp<\/code><\/pre>\n<p>This code snippet is basically what you would call a function in any higher-level language. In Assembly, it&#8217;s a <em>procedure<\/em>. In the C language, you would probably use the <em>atoi()<\/em> function to accomplish the same thing. In Assembly, you have to write your own code, similar to what&#8217;s shown above.<\/p>\n<p>This snippet isn&#8217;t the only procedure you&#8217;d have to code. For each and every program you wrote in Assembly, you&#8217;ve have to write procedures for everything. Eventually you do develop your own procedure library, which you can use over and over. That includes tasks such as converting a string to a value, but also math fucntions, trigonometry, graphics &#8212; you name it. That takes time, and it&#8217;s a pain.<\/p>\n<p>And I <em>loved<\/em> it!<\/p>\n<p>After a while, however, I realized how awkward it was to write things in Assembly. I&#8217;ve kept all my Assembly code that I wrote on my PCs. The dates range from 1984 through about 1988. That was when I began to code in C, primarily because the development time was so much faster. But I still remember Assembly language. Those were the days.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Assembly language runs fast. Assembly language produces small programs. But Assembly language takes nearly forever to write. That&#8217;s because you pretty much have to do everything from scratch.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[14],"class_list":["post-3448","post","type-post","status-publish","format-standard","hentry","category-main","tag-programming"],"_links":{"self":[{"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3448"}],"version-history":[{"count":11,"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3448\/revisions"}],"predecessor-version":[{"id":3466,"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3448\/revisions\/3466"}],"wp:attachment":[{"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wambooli.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}