

Charles Babbage, looking ahead to the sorts of problems his Analytical Engine would be able to solve, gave this example:

 What is the smallest positive integer whose square ends in the digits 269,696?

— Babbage, letter to Lord Bowden, 1837; see Hollingdale and Tootill, Electronic Computers, second edition, 1970, p. 125.

He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain.



Task[edit]
The task is to find out if Babbage had the right answer — and to do so, as far as your language allows it, in code that Babbage himself would have been able to read and understand.
As Babbage evidently solved the task with pencil and paper, a similar efficient solution is preferred.

For these purposes, Charles Babbage may be taken to be an intelligent person, familiar with mathematics and with the idea of a computer; he has written the first drafts of simple computer programmes in tabular form. [Babbage Archive Series L].



Motivation
The aim of the task is to write a program that is sufficiently clear and well-documented for such a person to be able to read it and be confident that it does indeed solve the specified problem.




 
36 35 34 33 32 31 00000008'010E0000' 0000     1 result: .ascid  "123456"                ;output buffer
                               0000  000E     2 retlen: .word   0                       ;$fao_s bytes written
         4C 55 21 00000018'010E0000' 0010     3 format: .ascid  "!UL"                   ;unsigned decimal
                                     001B     4
                               0000  001B     5 .entry  bab,0
                            55   D4  001D     6         clrl    r5                      ;result
                                     001F     7 10$:
                            55   D6  001F     8         incl    r5
             56   00   55   55   7A  0021     9         emul    r5,r5,#0,r6             ;mulr.rl, muld.rl, add.rl, prod.wq
    51   50   56   000F4240 8F   7B  0026    10         ediv    #1000000,r6,r0,r1       ;divr.rl, divd.rq, quo.wl, rem.wl
              51   00041D80 8F   D1  002F    11         cmpl    #269696,r1
                            E7   12  0036    12         bneq    10$                     ;not equal - try next
                                     0038    13
                                     0038    14         $fao_s -                        ;convert integer to text
                                     0038    15                  ctrstr = format, -
                                     0038    16                  outlen = retlen, -
                                     0038    17                  outbuf = result, -
                                     0038    18                  p1     = r5
                 B1 AF   C1 AF   B0  004A    19         movw    retlen, result          ;adjust length
                         AE AF   7F  004F    20         pushaq  result
              00000000'GF   01   FB  0052    21         calls   #1, g^lib$put_output
                                 04  0059    22         ret
                                     005A    23 .end    bab
$ run bab
25264
 