home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 4,380 of 4,675   
   Kerr-Mudd, John to John"   
   Re: shorter code to print a 16bit number   
   30 Jul 21 16:45:29   
   
   From: admin@nospicedham.127.0.0.1   
      
   On Fri, 30 Jul 2021 13:52:44 +0100   
   "Kerr-Mudd, John"  wrote:   
      
   > On Thu, 29 Jul 2021 22:11:00 -0700 (PDT)   
   > "luser...@nospicedham.gmail.com"  wrote:   
   >   
   > > I wrote this machine code to trace the LIT word in my forth interpreter.   
   > > Is it possible to tighten up this code? It's trying to print a 16bit signed   
   > > integer (ignoring INT_MIN) left to right with no leading zeros.   
   > >   
   >   
   []   
   > >   
   > I think I got the jist of it;   
   >   
   > here's some std asm code from earlier, rejigged for int 0x10 - it requires 5   
   free stack positions.   
   > uses ax,bx,cx,dx - 36 bytes   
      
    corrected version - 37   
      
   >   
   > PrtNum: ; ax to con using int10 fn 0E: no leading spaces or zeros but show   
   '-'   
   >          test ax,ax          ; Is it positive?   
   >          jge NotNeg   
   >         push ax   
   >          mov ax,0x0E00+'-'   
   >          int 0x10            ; bios prtc   
   >         pop ax   
   >          neg ax              ; show as positive: hibit set only for 0x8000!#   
   > NotNeg:   
   >          mov bx,10           ; decimal   
   >          xor cx,cx           ; Digit count (5 max)   
   > NextDigit:   
   >          inc cx              ; prt at least 1 digit (i.e. '0')   
   >          xor dx,dx           ; clear prev, cant cwd for #8000   
   >          div bx   
   >         push dx              ; Remainder is the digit   
   >          test ax,ax          ; Is it zero yet?   
   >          jnz NextDigit   
   > PutDigit:   
   >         pop ax               ; get digit (000x)   
      
   >          add ax,0x0E+'0'     ; digit to display value, prtfn in ah   
   I didn't test! Make that line:   
              add ax,0x0E00+'0'   ; digit to display value, prtfn in ah   
      
              int 0x10            ; bios prtc   
   >          loop PutDigit   
   >   
   >   
   >   
   >   
   >   
   >   
   >   
   > --   
   > Bah, and indeed Humbug.   
   >   
      
      
   --   
   Bah, and indeed Humbug.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca