home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / hp48 / 4482 < prev    next >
Encoding:
Text File  |  1992-09-04  |  18.8 KB  |  358 lines

  1. Newsgroups: comp.sys.hp48
  2. Path: sparky!uunet!gatech!darwin.sura.net!wupost!decwrl!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!e2big.mko.dec.com!engage.pko.dec.com!pinbot.enet.dec.com!ervin
  3. From: ervin@pinbot.enet.dec.com (Joseph James Ervin)
  4. Subject: Re: memory map & System RPL CREATETEMP
  5. Message-ID: <1992Sep4.124036.29197@engage.pko.dec.com>
  6. Sender: newsdaemon@engage.pko.dec.com (USENET News Daemon)
  7. Reply-To: ervin@pinbot.enet.dec.com (Joseph James Ervin)
  8. Organization: Digital Equipment Corporation
  9. References:  <2aa6b8de.1655comp.sys.hp48@hpcvbbs.cv.hp.com>
  10. Date: Fri, 4 Sep 1992 12:40:36 GMT
  11. Lines: 345
  12.  
  13.  
  14. In article <2aa6b8de.1655comp.sys.hp48@hpcvbbs.cv.hp.com>,
  15. akcs.rsanders@hpcvbbs.cv.hp.com (Robert Sanders) writes:
  16.  
  17. |>I've been working my way up from the many scattered (but informative!)
  18. |>tidbits about ML programming on the '48, but I don't really feel
  19. |>comfortable about what I'm doing unless I REALLY understand it. My main
  20. |>concerns now are about memory allocation using CREATETEMP.
  21.  
  22. You may find it easier to use a different routine that is not quite as
  23. low level.  Personally, I like to use the entry point that makes a string.
  24. Then I just modify the prolog and such to transform it into what I really
  25. want.  The nice thing about this is that it takes care of all the garbage 
  26. collection and such automatically.  
  27.  
  28. The symbol name of the entry point is: MAKE$N, and it creates a string
  29. with the body of the string N nibbles long, where N is passed in C.A.  On
  30. return, R0 points to the prolog of the string object, and D0 points to 
  31. the data section of the string.  
  32.  
  33.  
  34. |>
  35. |>1) I have a program that calls CREATETEMP.  I understand that if
  36. |>CREATETEMP returns with carry set, an allocation error has occurred. I
  37. |>then call GARBAGECOL (at #613e) and re-CREATETEMP.  However, I don't
  38. |>think I'm doing this correctly, as my program ( a string reverser, what
  39. |>else?) will work once (in low memory conditions) then corrupt the string.
  40. |>I'm obviously not interpreting GARBAGECOL's exit conditions correctly,
  41. |>but I can't get much information from EXPAND (PMC at #61c1c), and my
  42. |>disassembly of GARBAGECOL might take a while.  Has anyone done this
  43. |>already so that I can save a little time and study for finals? :)
  44. |>
  45. |>2) CREATETEMP moves the heap into the free space between what was the
  46. |>heap and the RPL stack.  However, I don't think I really understand what
  47. |>the memory areas referenced by the entries4 names RETTOP (saved B @
  48. |>#70574) and TEMPTOP (ptr @ #7056F) are (er, sorry for that weak
  49. |>sentence).  Does anyone have an informative memory map?  
  50. |> 
  51.  
  52. Below is my disassembly of a section of the HP48 ROM which creates a binary
  53. integer 13 nibbles long.  This is used by the TICKS command to create the
  54. 13 nibble binary integer into which is written the current TICKS value.
  55. This should give you an idea of how to use the CREATETEMP entry point in
  56. case you don't want to use the MAKE$N entry point described above.
  57.  
  58. I hope this helps.
  59.  
  60. >>>Joe Ervin
  61.  
  62.  
  63. ***********************************************************************
  64. ; This RPL command just puts 13d onto the stack as a system binary and then
  65. ; calls the RPL command to create a binary integer in TEMPOB.
  66. 0EDB9: ; *** create Binary Integer (13 nibbles) ***                             
  67. 0EDB9: 02D9D ! Program                                                          
  68. 0EDBE: 04071 ; <Dh>                                                             
  69. 0EDC3: 0EDE1 ; allocate Binary Integer (1:System Binary)                        
  70. 0EDC8: 0312B ! End Marker     
  71.  
  72.  
  73.  
  74. ; This RPL command creates a binary integer with the body of the binary number
  75. ; having the number of nibbles given by the system binary in 1:.
  76. 0EDE1: ; *** allocate Binary Integer (1:System Binary) ***                      
  77. 0EDE1: 02D9D ! Program                                                          
  78. 0EDE6: 055D5 ; Binary Integer template                                          
  79. 0EDEB: 03223 ; Internal SWAP                                                    
  80. 0EDF0: 61C1C ; allocate nibbles (2:sized object,1:System Binary)                
  81. 0EDF5: 0312B ! End Marker 
  82.  
  83.  
  84. HP:EXPAND
  85. 61C1C: ; *** allocate nibbles (2:sized object,1:System Binary) ***              
  86. 61C1C: 61C21 ! Machine Code at 61C21                                            
  87. 61C21: 8E7780     GOSUBL 6249E    ; MC XFER: pop stk1 (System Binary) into A.A. 
  88. 61C27: 8FB9760    GOSBVL 0679B    ; MC: save D0,D1,B,D (uses C,D0), clear carry 
  89. 61C2E: D8         B=A    A     ; Move size of object into B.a. 
  90. 61C30: 147        C=DAT1 A    ; Get the next address from stack to level 1. 
  91.                 ; This points to the template for the object 
  92.                 ; type being created. 
  93. 61C33: 137        CD1EX         ; Point D1 to that template, C to stack level
  94.                 ; 1. 
  95. 61C36: 174        D1=D1+ 5    ; Point to the size field of the template.  
  96.                 ; This indicates how many more nibbles than the
  97.                 ; requested size we need to allocate for the
  98.                 ; expanded object.
  99. 61C39: 143        A=DAT1 A    ; Get the size field of the template into A. 
  100. 61C3C: C8         B=B+A  A    ; Add this many nibbles to the requested size 
  101.                 ; of the object.
  102. 61C3E: 137        CD1EX     ; Point D1 to stack level 1, C to the size
  103.                 ; field of the template.
  104. 61C41: 06         RSTK=C       ; Save template pointer. 
  105. 61C43: D9         C=B    A    ; Get # of nibbles into C. 
  106. 61C45: 24         P=     4                                                      
  107. 61C47: 809        C+P+1        ; Add 5 nibbles to C.  C now contains the 
  108.                 ; number of nibbles to allocate from memory, 
  109.                 ; including what will be used by the object's
  110.                 ; prolog. 
  111. 61C4A: 06         RSTK=C    ; Save # of nibbles to allocate. 
  112. 61C4C: 84A        ST=0   10    ; Clear ST<10> which is used for GC tracking. 
  113. 61C4F: 07         C=RSTK    ; Pop the # of nibbles to allocate. 
  114. 61C51: 06         RSTK=C    ; Push the number of nibbles to allocate.   
  115. 61C53: 8F8DA60    GOSBVL 06AD8    ; HP:CREATETEMP (A = malloc(C nibbles)). 
  116. 61C5A: 5E3        GONC   61C99    ; If no error, then continue at 61c99. 
  117. 61C5D: 86A01      ?ST=0  10     ; Have we done GC already? 
  118.                   GOYES  61C70                                                  
  119. 61C62: 07         C=RSTK                                                        
  120. 61C64: 07         C=RSTK                                                        
  121. 61C66: 8E0480     GOSUBL 624AC    ; MC XFER: restore D,B,D1,D0 (C=D0), 
  122.                 ; clear carry. 
  123. 61C6C: 6051       GOTO   61DBD                                                  
  124.                                                                                 
  125. 61DBD: 8DBBF40    GOVLNG 04FBB    ; MC: Error: Insufficient Memory   
  126.  
  127. 61C99: 07         C=RSTK    ; Pop # of nibbles allocated, for the new 
  128.                 ; object, including the prolog, but excluding 
  129.                 ; the 6 nibbles of TEMPOB overhead.
  130. 61C9B: D5         B=C    A     ; Save it in B. 
  131. 61C9D: 07         C=RSTK    ; Pop pointer into object template. 
  132. 61C9F: 136        CD0EX      ; Point D0 to second word in template, C to 
  133.                 ; top of TEMPOB+1. 
  134. 61CA2: 06         RSTK=C     ; Push pointer top of TEMPOB+1. 
  135. 61CA4: 137        CD1EX        ; Point C to 5 nibbles into the newly allocated
  136.                 ; TEMPOB RAM. D1 to top of TEMPOB+1.  This is
  137.                 ; where the new object will start, i.e. where
  138.                 ; it's prolog will be written.
  139. 61CA7: 146        C=DAT0 A       ; Get the object's excess size from the 
  140.                 ; object template. 
  141. 61CAA: 24         P=     4                                                      
  142. 61CAC: 809        C+P+1       ; Add 5 to the object's excess size to account
  143.                 ; for its prolog. 
  144. 61CAF: D7         D=C    A      ; Save the size of the prolog+size field in D. 
  145. 61CB1: 184        D0=D0- 5     ; Back up to the template's prolog. 
  146. 61CB4: 8FC0760    GOSBVL 0670C    ; HP:MOVEDOWN, 
  147.                 ; blockcopy (D0:src,D1:dst,C.A=nibbles).  This 
  148.                 ; copies the template object pointed to by D0
  149.                 ; into the TEMPOB area pointed to by D1. 
  150. 61CBB: 07         C=RSTK     ; Pop the pointer to the start of the new
  151.                 ; object. 
  152. 61CBD: 136        CD0EX        ;  
  153. 61CC0: D9         C=B    A     ; C Gets number of nibbles allocated.
  154. 61CC2: 136        CD0EX         ; And swap # of nibbles allocated into D0. 
  155. 61CC5: 184        D0=D0- 5    ; Take away 5 nibbles for the object's prolog. 
  156. 61CC8: 136        CD0EX                                                         
  157. 61CCB: 164        D0=D0+ 5    ; Add 5 to the starting address of the object. 
  158. 61CCE: 144        DAT0=C A    ; ...and write out the object's size into its
  159.                 ; size field.  The new object in TEMPOB now has 
  160.                 ; a valid prolog and size field. 
  161. 61CD1: 184        D0=D0- 5    ; Back up to the start of the object. 
  162. 61CD4: D9         C=B    A    ; C gets the size of the object, including the
  163.                 ; object's body, prolog, and size field. 
  164. 61CD6: EB         C=C-D  A    ; Subract off the nibbles used up in the 
  165.                 ; prolog and size field, so C contains the
  166.                 ; size of the data field of the object. 
  167. 61CD8: 8FC5760    GOSBVL 0675C    ; Clear C nibbles starting at D1 and 
  168.                 ; and incrementing.  This just clears out the
  169.                 ; body of the object.  
  170. 61CDF: 132        AD0EX        ; Point D0 at the start of the object. 
  171. 61CE2: 8D27630    GOVLNG 03672    ; Restore regs, Overwrite the level 1 stack
  172.                 ; entry (a pointer) to point at the newly
  173.                 ; created object in TEMP0B, and continue RPL. 
  174.  
  175. ; *****************************************************************
  176. ; HP: CREATETEMP
  177. 06AD8: ; *** MC: A = malloc(C nibbles)  ***                                   
  178. 06AD8: 20         P=     0                                                      
  179. 06ADA: 818F25     C=C+CON A,6          ; Add 6 nibbles to the amount to
  180.                     ; allocate.  This leaves room in TEMPOB
  181.                     ; for a counter indicating the number
  182.                     ; of nibbles which were allocated, and
  183.                     ; one nibble for a GC flag (used by
  184.                     ; the garbage collection routine). 
  185. 06AE0: 400        RTNC                                                          
  186. 06AE3: ; *** A=malloc(C Nibbles) ***                                            
  187. 06AE3: D5         B=C    A        ; Number of nibbles to allocate. 
  188. 06AE5: 1F97507    D1=HEX 70579          ; saved D1 (RPL stack pointer)          
  189. 06AEC: 147        C=DAT1 A                                                      
  190. 06AEF: 1F47507    D1=HEX 70574          ; saved B (return stack pointer)        
  191. 06AF6: 143        A=DAT1 A                                                      
  192. 06AF9: E2         C=C-A  A         ; How many free nibbles are there? 
  193. 06AFB: E9         C=C-B  A        ; Return with carry if we need to GC.  
  194. 06AFD: 400        RTNC                                                          
  195. 06B00: ; *** A=malloc(B Nibbles) (C.A=free nibbles) ***                         
  196. 06B00: 7A8F       GOSUB  06A8E          ; Let C.A = C.A / 5                     
  197. 06B04: 1BE6607    D0=HEX 7066E          ; saved D (free stack space)            
  198. 06B0B: 144        DAT0=C A        ; Update with the new amount of free 
  199.                     ; space. 
  200. 06B0E: 1BF6507    D0=HEX 7056F          ; D0 gets pointer to top of TEMPOB 
  201.                     ; memory (grows towards higher 
  202.                     ; addresses). 
  203. 06B15: 146        C=DAT0 A              ; Point D0 at top of TEMPOB memory.
  204. 06B18: C9         C=C+B  A              ; Move top of temp memory up by B
  205.                     ; nibbles, thus allocating storage in
  206.                     ; the temp object area. 
  207. 06B1A: 144        DAT0=C A              ; Update pointer to top of temp mem. 
  208. 06B1D: 143        A=DAT1 A          ; Get pointer to top of Return stack.
  209. 06B20: 130        D0=A            ; Point D0 to top of return stack. 
  210. 06B23: C0         A=A+B  A           ; Return stack gets moved up by B
  211.                     ; nibbles as well.  This is because the
  212.                     ; return stack sits on top of tempob,
  213.                     ; so when tempob grows, the return 
  214.                     ; stack needs to be pushed up in
  215.                     ; memory.
  216. 06B25: 141        DAT1=A A        ; Write new return stack pointer. 
  217. 06B28: 131        D1=A            ; and point D1 to the NEW top of 
  218.                     ; return stack. 
  219. 06B2B: EE         C=A-C  A         ; C=^top of return stack - ^top of
  220.                     ; tempob memory.  Thus C= size of 
  221.                     ; the return address stack. 
  222. 06B2D: 788B       GOSUB  066B9         ; Move the return address stack up to 
  223.                     ; its new location. HP:MOVEUP.
  224. 06B31: 160        D0=D0+ 1         ; Point D0 to top of old TEMPOB+1.    
  225. 06B34: 1C4        D1=D1- 5         ; Point D1 5 nibbles back from the 
  226.                     ; top of the new TEMPOB.
  227. 06B37: D9         C=B    A        ; and write the number of nibbles just
  228.                     ; allocated into the first 5 nibbles
  229.                     ; of TEMPOB.  This value is used by
  230.                     ; the garbage collection routine to
  231.                     ; navigate through the TEMPOB area.
  232. 06B39: 145        DAT1=C A                                                      
  233. 06B3C: 03         RTNCC  
  234.  
  235.  
  236. ; *****************************************************************
  237. ; HP: MOVEUP, Block transfer.  Used to move the return address stack UP to 
  238. ; its new location after allocating storage in TEMPOB.
  239. ; This routine expects:
  240. ; D0    ; Source pointer.
  241. ; D1    ; destination pointer.
  242. ; C.a    ; nibble count.
  243. ;
  244. ; The loop that does the move/decrement/loop action is heavily optimized for
  245. ; speed.  The nibble count is shifted down by a nibble so that they can count
  246. ; words and use word-wide moves for speed.  The decrement at the bottom of the
  247. ; loop is like this: first it decrements only the bottom byte, then when that 
  248. ; rolls over it decrements the next nibble (xs), then when that rolls over, 
  249. ; it decrements the top nibble.  Then when the word-count is zero, it finishes
  250. ; up the move by moving the excess nibbles.
  251. 066B9: CE         C=C-1  A          ; Decrement nibble count. 
  252. 066BB: 4C4        GOC    06708        ; Branch to end if done. 
  253. 066BE: 80D0       P=C    0        ; P saves excess nibble count-1 (see
  254.                     ; below). 
  255. 066C2: F6         CSR    A        ; C now holds the number of words to 
  256.                     ; move. 
  257. 066C4: CE         C=C-1  A        ; Decrement the word count. 
  258. 066C6: 442        GOC    066EB        ; If we're done with the words, then 
  259.                     ; continue moving the excess nibbles. 
  260. 066C9: 18F        D0=D0- 16        ; Decrement the source pointer.
  261. 066CC: 1CF        D1=D1- 16        ; Decrement the destination pointer.
  262. 066CF: 1527       A=DAT0 W             ; Move a word. 
  263. 066D3: 1517       DAT1=A W 
  264. 066D7: A6E        C=C-1  B        ; Decrement the low byte of the
  265.                     ; word counter. 
  266. 066DA: 5EE        GONC   066C9        ; Continue until done or until 255 
  267.                     ; words have been moved. 
  268. 066DD: A2E        C=C-1  XS        ; Decrement the next higher nibble of 
  269.                     ; the nibble count... 
  270. 066E0: 58E        GONC   066C9        ; ...and continue if not done yet. 
  271. 066E3: B36        C=C+1  X            ; Else increment the word count. 
  272. 066E6: CE         C=C-1  A        ; and decrement the next piece of the 
  273.                     ; count. 
  274. 066E8: 50E        GONC   066C9         ; and continue if not done. 
  275. 066EB: D2         C=0    A                                                      
  276. 066ED: 809        C+P+1         ; C=excess nibble count. 
  277. 066F0: 132        AD0EX                                                         
  278. 066F3: EA         A=A-C  A        ; Decrement source pointer by excess
  279.                     ; nibbles.  
  280. 066F5: 130        D0=A             
  281. 066F8: 133        AD1EX                                                         
  282. 066FB: EA         A=A-C  A        ; Do the same thing to the destination
  283.                     ; pointer. 
  284. 066FD: 131        D1=A                                                          
  285. 06700: 1521       A=DAT0 WP        ; Move the excess nibbles. 
  286. 06704: 1511       DAT1=A WP             ; ... 
  287. 06708: 20         P=     0                                                      
  288. 0670A: 03         RTNCC            ; Exit with D0 pointing to the bottom
  289.                     ; of the old return stack (oldest 
  290.                     ; return address), and with D1 
  291.                     ; pointing to the
  292.                     ; top of the return address stack.
  293.  
  294.  
  295. ; *****************************************************************
  296. ; HP: MOVEDOWN.  See comments on MOVEUP.
  297. 0670C: ; *** MC: block copy (D0:src,D1:dst,C.A=nibbles) ***                     
  298. 0670C: CE         C=C-1  A        ; Decrement 1 from num of nibbles. 
  299. 0670E: 494        GOC    06758                                                  
  300. 06711: 80D0       P=C    0                                                      
  301. 06715: F6         CSR    A          ; Number of 16 nibble words to move. 
  302. 06717: CE         C=C-1  A                                                      
  303. 06719: 442        GOC    0673E                                                  
  304. 0671C: 1527       A=DAT0 W           ; Move a word. 
  305. 06720: 1517       DAT1=A W                                                      
  306. 06724: 16F        D0=D0+ 16                                                     
  307. 06727: 17F        D1=D1+ 16                                                     
  308. 0672A: A6E        C=C-1  B        ; Decrement.b 
  309. 0672D: 5EE        GONC   0671C                                                  
  310. 06730: A2E        C=C-1  XS        ; decrement... 
  311. 06733: 58E        GONC   0671C                                                  
  312. 06736: B36        C=C+1  X                                                      
  313. 06739: CE         C=C-1  A        ; decrement... 
  314. 0673B: 50E        GONC   0671C                                                  
  315. 0673E: 1521       A=DAT0 WP           ; Move the remaining nibbles. 
  316. 06742: 1511       DAT1=A WP                                                     
  317. 06746: 136        CD0EX                                                         
  318. 06749: 809        C+P+1                                                         
  319. 0674C: 134        D0=C                                                          
  320. 0674F: 137        CD1EX                                                         
  321. 06752: 809        C+P+1                                                         
  322. 06755: 135        D1=C                                                          
  323. 06758: 20         P=     0                                                      
  324. 0675A: 03         RTNCC  
  325.  
  326.  
  327.  
  328. ; *****************************************************************
  329. ; Previously undocumented.
  330. 0675C: AF0        A=0    W                                                      
  331. 0675F: CE         C=C-1  A        ; Decrement the number of nibbles. 
  332. 06761: 453        GOC    06797        ; Skip to bottom if done. 
  333. 06764: 80D0       P=C    0        ; Save excess nibbles-1 in P. 
  334. 06768: F6         CSR    A           ; Count words. 
  335. 0676A: CE         C=C-1  A          ; Decrement number of words. 
  336. 0676C: 4D1        GOC    0678A        ; If done, then skip down. 
  337. 0676F: 1517       DAT1=A W            ; Else clear a word. 
  338. 06773: 17F        D1=D1+ 16           ; Move to next word. 
  339. 06776: A6E        C=C-1  B        ; Decrement.b the word count. 
  340. 06779: 55F        GONC   0676F                                                  
  341. 0677C: A2E        C=C-1  XS         ; decrement... 
  342. 0677F: 5FE        GONC   0676F                                                  
  343. 06782: B36        C=C+1  X                                                      
  344. 06785: CE         C=C-1  A         ; decrement... 
  345. 06787: 57E        GONC   0676F
  346. 0678A: 1511       DAT1=A WP        ; Zero out the excess nibbles. 
  347. 0678E: 137        CD1EX                                                         
  348. 06791: 809        C+P+1            ; post-increment D1... 
  349. 06794: 135        D1=C                                                          
  350. 06797: 20         P=     0                                                      
  351. 06799: 03         RTNCC            ; ...and return with D1 pointing to the
  352.                     ; address one higher than the last one
  353.                     ; cleared.  
  354.  
  355.  
  356.  
  357.  
  358.