<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.intellivision.us/index.php?action=history&amp;feed=atom&amp;title=Prnum32.asm</id>
		<title>Prnum32.asm - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.intellivision.us/index.php?action=history&amp;feed=atom&amp;title=Prnum32.asm"/>
		<link rel="alternate" type="text/html" href="http://wiki.intellivision.us/index.php?title=Prnum32.asm&amp;action=history"/>
		<updated>2026-07-28T14:07:14Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://wiki.intellivision.us/index.php?title=Prnum32.asm&amp;diff=14873&amp;oldid=prev</id>
		<title>Mr z: Protected &quot;Prnum32.asm&quot; ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite))</title>
		<link rel="alternate" type="text/html" href="http://wiki.intellivision.us/index.php?title=Prnum32.asm&amp;diff=14873&amp;oldid=prev"/>
				<updated>2010-12-04T09:06:27Z</updated>
		
		<summary type="html">&lt;p&gt;Protected &amp;quot;&lt;a href=&quot;/index.php/Prnum32.asm&quot; title=&quot;Prnum32.asm&quot;&gt;Prnum32.asm&lt;/a&gt;&amp;quot; ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite))&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 09:06, 4 December 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Mr z</name></author>	</entry>

	<entry>
		<id>http://wiki.intellivision.us/index.php?title=Prnum32.asm&amp;diff=2993&amp;oldid=prev</id>
		<title>Mr z at 06:32, 8 September 2008</title>
		<link rel="alternate" type="text/html" href="http://wiki.intellivision.us/index.php?title=Prnum32.asm&amp;diff=2993&amp;oldid=prev"/>
				<updated>2008-09-08T06:32:41Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Programming]] [[Category:Library]]&lt;br /&gt;
&lt;br /&gt;
= Functions Provided =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;CENTER&amp;gt;&amp;lt;TABLE BORDER&amp;gt;&amp;lt;TR&amp;gt;&amp;lt;TH&amp;gt;Entry point&amp;lt;/TH&amp;gt;&amp;lt;TH&amp;gt;Function provided&amp;lt;/TH&amp;gt;&amp;lt;TH&amp;gt;Notes&amp;lt;/TH&amp;gt;&amp;lt;/TR&amp;gt;&lt;br /&gt;
&amp;lt;TR&amp;gt;&amp;lt;TD&amp;gt;PRNUM32.l&amp;lt;/TD&amp;gt;&amp;lt;TD ROWSPAN=3&amp;gt;Print a 32-bit decimal number&amp;lt;/TD&amp;gt;&amp;lt;TD&amp;gt;Prints the number left-justified.  (The name is PRNUM32.l with a lower-case L at the end, not a 1.)&amp;lt;/TD&amp;gt;&amp;lt;/TR&amp;gt;&lt;br /&gt;
&amp;lt;TR&amp;gt;&amp;lt;TD&amp;gt;PRNUM32.b&amp;lt;/TD&amp;gt;&amp;lt;TD&amp;gt;Prints the number with leading blanks, right justified in a fixed-width field.&amp;lt;/TD&amp;gt;&amp;lt;/TR&amp;gt;&lt;br /&gt;
&amp;lt;TR&amp;gt;&amp;lt;TD&amp;gt;PRNUM32.z&amp;lt;/TD&amp;gt;&amp;lt;TD&amp;gt;Prints the number with leading zeros, right justified in a fixed-width field.&amp;lt;/TD&amp;gt;&amp;lt;/TR&amp;gt;&amp;lt;/TABLE&amp;gt;&amp;lt;/CENTER&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
See source code below for calling convention.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
&lt;br /&gt;
(todo... please contribute!)&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
This function uses [[prnum16.asm]].  Therefore, you will need to include both this and [[prnum16.asm]] in your application if you're printing 32-bit numbers.&lt;br /&gt;
&lt;br /&gt;
= Source Code =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
;* ======================================================================== *;&lt;br /&gt;
;*  These routines are placed into the public domain by their author.  All  *;&lt;br /&gt;
;*  copyright rights are hereby relinquished on the routines and data in    *;&lt;br /&gt;
;*  this file.  -- Joseph Zbiciak, 2008                                     *;&lt;br /&gt;
;* ======================================================================== *;&lt;br /&gt;
&lt;br /&gt;
    IF (DEFINED PRNUM16) AND ((DEFINED _WITH_PRNUM32)) = 0&lt;br /&gt;
        ERR &amp;quot;Must INCLUDE PRNUM16 after PRNUM32.&amp;quot;&lt;br /&gt;
    ENDI&lt;br /&gt;
&lt;br /&gt;
;; ======================================================================== ;;&lt;br /&gt;
;;  PRNUM32.l     -- Print an unsigned 32-bit number left-justified.        ;;&lt;br /&gt;
;;  PRNUM32.b     -- Print an unsigned 32-bit number with leading blanks.   ;;&lt;br /&gt;
;;  PRNUM32.z     -- Print an unsigned 32-bit number with leading zeros.    ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;  AUTHOR                                                                  ;;&lt;br /&gt;
;;      Joseph Zbiciak  &amp;lt;im14u2c AT globalcrossing DOT net&amp;gt;                 ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;  REVISION HISTORY                                                        ;;&lt;br /&gt;
;;      30-Mar-2003 Initial complete revision                               ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;  INPUTS for all variants                                                 ;;&lt;br /&gt;
;;      R0  Lower 16 bits of number to print                                ;;&lt;br /&gt;
;;      R1  Upper 16 bits of number to print                                ;;&lt;br /&gt;
;;      R2  Width of field.  Must be &amp;gt;= 5.  Ignored by PRNUM32.l.           ;;&lt;br /&gt;
;;      R3  Format word, added to digits to set the color, etc.             ;;&lt;br /&gt;
;;          Note:  Bit 15 is ignored and manipulated internally.            ;;&lt;br /&gt;
;;      R4  Pointer to location on screen to print number                   ;;&lt;br /&gt;
;;      R5  Return address                                                  ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;  OUTPUTS                                                                 ;;&lt;br /&gt;
;;      R0  Zeroed                                                          ;;&lt;br /&gt;
;;      R1  Trashed                                                         ;;&lt;br /&gt;
;;      R2  Unmodified                                                      ;;&lt;br /&gt;
;;      R3  Unmodified, except for bit 15, which may be set.                ;;&lt;br /&gt;
;;      R4  Points to first character after field.                          ;;&lt;br /&gt;
;;      R5  Trashed                                                         ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;  DESCRIPTION                                                             ;;&lt;br /&gt;
;;      These routines print unsigned 32-bit numbers in a field 5 to 10     ;;&lt;br /&gt;
;;      positions wide.  The number is printed either in left-justified     ;;&lt;br /&gt;
;;      or right-justified format.  Right-justified numbers are padded      ;;&lt;br /&gt;
;;      with leading blanks or leading zeros.  Left-justified numbers       ;;&lt;br /&gt;
;;      are not padded on the right.                                        ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;      See PRNUM16 for a table illustrating output formats.                ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;  TECHNIQUES                                                              ;;&lt;br /&gt;
;;      This routine uses a 32-by-16 integer divide to cut the 32-bit       ;;&lt;br /&gt;
;;      number into two 5-digit segments.  It divides the initial number    ;;&lt;br /&gt;
;;      by 100000.  The quotient provides the upper half, and the           ;;&lt;br /&gt;
;;      remainder provides the lower half.                                  ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;      Both halves are printed by reusing the PRNUM16 routines.  The       ;;&lt;br /&gt;
;;      lower half is always printed using PRNUM16.z.  The upper half is    ;;&lt;br /&gt;
;;      printed using one of PRNUM16.l, PRNUM16.b, or PRNUM16.z, based on   ;;&lt;br /&gt;
;;      which entry point the caller used for invoking PRNUM32.             ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;      The number in the lower half can be in the range 00000...99999.     ;;&lt;br /&gt;
;;      Some of this range is outside the range of a 16-bit value.  We      ;;&lt;br /&gt;
;;      handle this by passing a special flag to PRNUM16 in bit 15 of       ;;&lt;br /&gt;
;;      the format word.  When set, PRNUM16 will add '5' to the leading     ;;&lt;br /&gt;
;;      digit of the number.  When clear, it leaves it unmodified.          ;;&lt;br /&gt;
;;      Thus, when our lower half is in the range 65536...99999, we cope    ;;&lt;br /&gt;
;;      by adding 15536 to the lower 16 bits and setting the &amp;quot;add 5&amp;quot; flag.  ;;&lt;br /&gt;
;;      This works, because the lower 16 bits are in the range 0 - 34463.   ;;&lt;br /&gt;
;;      After the 'tweak', they're in the range 15536 - 49999.              ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;  NOTES                                                                   ;;&lt;br /&gt;
;;      The left-justified variant ignores the field width.                 ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;      This code is fully reentrant, although it has a significant stack   ;;&lt;br /&gt;
;;      footprint.                                                          ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;      This code does not handle numbers which are too large to be         ;;&lt;br /&gt;
;;      displayed in the provided field.  If the number is too large,       ;;&lt;br /&gt;
;;      non-digit characters will be displayed in the initial digit         ;;&lt;br /&gt;
;;      position.  Also, the run time of this routine may get excessively   ;;&lt;br /&gt;
;;      large, depending on the magnitude of the overflow.                  ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;      This code requires PRNUM16.  Since PRNUM16 requires a minor tweak   ;;&lt;br /&gt;
;;      to support PRNUM32, it must either be included after PRNUM32, or    ;;&lt;br /&gt;
;;      assembled with the symbol &amp;quot;_WITH_PRNUM32&amp;quot; set.                      ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;  CODESIZE                                                                ;;&lt;br /&gt;
;;      81 words  (not including PRNUM16.)                                  ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;      To save code size, you can define the following symbols to omit     ;;&lt;br /&gt;
;;      some variants:                                                      ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;              _NO_PRNUM32.l:   Disables PRNUM32.l.  Saves 8 words.        ;;&lt;br /&gt;
;;              _NO_PRNUM32.b:   Disables PRNUM32.b.  Saves 8 words.        ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;      Defining both symbols saves 18 words total, because it omits        ;;&lt;br /&gt;
;;      some code shared by both routines.                                  ;;&lt;br /&gt;
;;                                                                          ;;&lt;br /&gt;
;;  STACK USAGE                                                             ;;&lt;br /&gt;
;;      This function uses up to 8 words of stack space.  That includes     ;;&lt;br /&gt;
;;      4 words of stack space consumed by PRNUM16 when printing the        ;;&lt;br /&gt;
;;      two halves of the number.                                           ;;&lt;br /&gt;
;; ======================================================================== ;;&lt;br /&gt;
    IF (DEFINED PRNUM32) = 0&lt;br /&gt;
PRNUM32 PROC&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    IF (DEFINED _NO_PRNUM32.l) = 0&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
        ;;  PRNUM32.l:  Print unsigned, left-justified.                     ;;&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
&lt;br /&gt;
@@l:    TSTR    R1&lt;br /&gt;
        BEQ     PRNUM16.l&lt;br /&gt;
        PSHR    R5&lt;br /&gt;
        MVII    #PRNUM16.l, R5&lt;br /&gt;
        B       @@com&lt;br /&gt;
    ENDI&lt;br /&gt;
&lt;br /&gt;
    IF (DEFINED _NO_PRNUM32.b) = 0&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
        ;;  PRNUM32.b:  Print unsigned with leading blanks.                 ;;&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
@@b:    TSTR    R1&lt;br /&gt;
        BEQ     PRNUM16.b&lt;br /&gt;
        PSHR    R5&lt;br /&gt;
        MVII    #PRNUM16.b, R5&lt;br /&gt;
        B       @@com&lt;br /&gt;
    ENDI&lt;br /&gt;
&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
        ;;  PRNUM32.z:  Print unsigned with leading zeros.                  ;;&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
@@z:    TSTR    R1&lt;br /&gt;
        BEQ     PRNUM16.z&lt;br /&gt;
        PSHR    R5&lt;br /&gt;
    IF NOT ((DEFINED _NO_PRNUM32.l) AND (DEFINED _NO_PRNUM32.b))&lt;br /&gt;
        MVII    #PRNUM16.z, R5&lt;br /&gt;
    ENDI&lt;br /&gt;
&lt;br /&gt;
@@com   PSHR    R2              ; save our field width&lt;br /&gt;
        PSHR    R3              ; save our format word&lt;br /&gt;
&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
        ;;  Divide the 32-bit number by 100000, and remember the remainder. ;;&lt;br /&gt;
        ;;  This will give us two 5-digit numbers for the two halves.       ;;&lt;br /&gt;
        ;;  The upper half will always be in the range 0 to 42949, and so   ;;&lt;br /&gt;
        ;;  we can print it with one of the PRNUM16 routines.  The lower    ;;&lt;br /&gt;
        ;;  half is in the range 0...99999, so we have to do some fancy     ;;&lt;br /&gt;
        ;;  footwork in the case that it's above 65535.                     ;;&lt;br /&gt;
        ;;                                                                  ;;&lt;br /&gt;
        ;;  The loop below looks like it divides by 50000, but really we've ;;&lt;br /&gt;
        ;;  aligned the divisor within a 16-bit number.                     ;;&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
&lt;br /&gt;
        MVII    #50000, R2      ; 100000, right shifted by 1.&lt;br /&gt;
        MVII    #1,     R3      ; Divide is done when this bit falls out of R3&lt;br /&gt;
        B       @@div1          ; jump to the first divide step.&lt;br /&gt;
&lt;br /&gt;
@@div:  RLC     R0,     1       ;\__ 32 bit left shift of numerator.&lt;br /&gt;
        RLC     R1,     1       ;/   &lt;br /&gt;
        BC      @@divf          ; last shift overflowed, force a subtract&lt;br /&gt;
&lt;br /&gt;
@@div1: CMPR    R2,     R1      ; can we subtract from upper half?&lt;br /&gt;
        BNC     @@divn          ; nope, then don't subtract.&lt;br /&gt;
&lt;br /&gt;
@@divf: SUBR    R2,     R1      ; subtract upper half. &lt;br /&gt;
        SETC                    ; usu. the SUBR sets carry, except when forced&lt;br /&gt;
&lt;br /&gt;
@@divn: RLC     R3,     1       ; left-shift the quotient, including new bit&lt;br /&gt;
        BNC     @@div           ; loop until quotient is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
        ;;  At this point, R1:R0 is our remainder, and R3 is our quotient.  ;;&lt;br /&gt;
        ;;  The remainder occupies the upper 17 bits of the R1:R0 pair.     ;;&lt;br /&gt;
        ;;  For now, hide this on the stack.  We do this dance carefully    ;;&lt;br /&gt;
        ;;  since we need to restore two items from the stack as well,      ;;&lt;br /&gt;
        ;;  and we don't want to lose the values in R4 or R5 either.        ;;&lt;br /&gt;
        ;;                                                                  ;;&lt;br /&gt;
        ;;  If there was no &amp;quot;upper half&amp;quot; (eg. our value is 65536...99999)   ;;&lt;br /&gt;
        ;;  go handle that case specially.  Urgl.                           ;;&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
&lt;br /&gt;
        SLLC    R0,     1       ; put 17th bit into carry&lt;br /&gt;
        MOVR    R3,     R0      ; save quotient into R0&lt;br /&gt;
        PULR    R3              ; recall our format word into R3&lt;br /&gt;
        PULR    R2              ; recall our field width&lt;br /&gt;
&lt;br /&gt;
        RLC     R1,     1       ; R1 is bits 15 downto 0 of remainder&lt;br /&gt;
        SLL     R3,     1       ; \_ Force bit 15 of format word to 1 or 0.  &lt;br /&gt;
        RRC     R3,     1       ; /  This will add 5 to leading digit.&lt;br /&gt;
        TSTR    R3              ;&lt;br /&gt;
        BPL     @@lt64k         ; if there was no carry, rmdr is 0...65535&lt;br /&gt;
        ADDI    #15536, R1      ; add &amp;quot;15536&amp;quot; to rest of digits &lt;br /&gt;
@@lt64k:&lt;br /&gt;
        TSTR    R0&lt;br /&gt;
        BEQ     @@notop         ; convert bottom into top if top = 0.&lt;br /&gt;
&lt;br /&gt;
        PSHR    R2              ; save field width on stack&lt;br /&gt;
        PSHR    R3              ; save format word for bottom half&lt;br /&gt;
        PSHR    R1              ; save quotient for bottom half&lt;br /&gt;
&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
        ;;  Go ahead and print the first 5 digits of the result.            ;;&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
        SUBI    #5,     R2      ; bottom accounts for 5 digits of field width&lt;br /&gt;
        ANDI    #$7FFF, R3      ; force bit 15 of R3 clear.&lt;br /&gt;
&lt;br /&gt;
    IF (DEFINED _NO_PRNUM32.l) AND (DEFINED _NO_PRNUM32.b)&lt;br /&gt;
        CALL    PRNUM16.z&lt;br /&gt;
    ELSE&lt;br /&gt;
        MOVR    R5,     R1      ; R5 contains branch target.&lt;br /&gt;
        MVII    #@@ret, R5      ; remember return address.&lt;br /&gt;
        MOVR    R1,     PC      ; call one of PRNUM16.z, .b, or .l as needed&lt;br /&gt;
@@ret:  &lt;br /&gt;
    ENDI&lt;br /&gt;
&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
        ;;  Print the bottom half of the number.   We branch into the       ;;&lt;br /&gt;
        ;;  heart of PRNUM16, which effectively always leads with zeros.    ;;&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
        MVII    #4,     R2      ; bottom is always exactly 5 digits.&lt;br /&gt;
        PULR    R0              ; get bits 15 downto 0 of remainder&lt;br /&gt;
        PULR    R3              ; get format word.&lt;br /&gt;
        INCR    SP              ; save garbage in R1 slot on stack&lt;br /&gt;
        MVII    #_PW10, R1      ; need to set up power-of-10 pointer first&lt;br /&gt;
        B       PRNUM16.dig1    ; chain return via PRNUM16.digit&lt;br /&gt;
&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
        ;;  If there was no &amp;quot;upper half&amp;quot;, convert the &amp;quot;lower half&amp;quot; into an  ;;&lt;br /&gt;
        ;;  upper half.  This actually isn't too gross.                     ;;&lt;br /&gt;
        ;; ---------------------------------------------------------------- ;;&lt;br /&gt;
@@notop:&lt;br /&gt;
        MOVR    R1,     R0      ; convert bottom half to top half&lt;br /&gt;
    IF (DEFINED _NO_PRNUM32.l) AND (DEFINED _NO_PRNUM32.b)&lt;br /&gt;
        PULR    R5&lt;br /&gt;
        B       PRNUM16.z&lt;br /&gt;
    ELSE&lt;br /&gt;
        MOVR    R5,     R1      ; \ &lt;br /&gt;
        PULR    R5              ;  |__ chain return via target PRNUM16 routine&lt;br /&gt;
        JR      R1              ; /&lt;br /&gt;
    ENDI&lt;br /&gt;
&lt;br /&gt;
        ENDP&lt;br /&gt;
    ENDI&lt;br /&gt;
        &lt;br /&gt;
;; ======================================================================== ;;&lt;br /&gt;
;;  End of File:  prnum32.asm                                               ;;&lt;br /&gt;
;; ======================================================================== ;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mr z</name></author>	</entry>

	</feed>