home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / basic / mbextend.lbr / RELOC.AZM / RELOC.ASM
Encoding:
Assembly Source File  |  1988-01-24  |  2.8 KB  |  106 lines

  1. ; Reprinted from Micro/Systems Journal, Vol. 1, No. 1, March-
  2. ; April 1985, article titled "Assembly Language Extensions for
  3. ; MS-Basic" by Ron Kreymborg.  
  4. ;
  5.  
  6. ;**************************************************************;
  7. ; RELOC:   A program to move a page relocatable assembly       ;
  8. ;     language module with an origin at zero to the top      ;
  9. ;       of available memory.                                   ;
  10. ;                                                              ;
  11. ;                         Ron Kreymborg     ;
  12. ;                                                              ;
  13. ; This code resides at the end of MBASIC                       ;
  14. ;**************************************************************;
  15.  
  16.     org    6000h
  17.  
  18. exit:    jmp    0        ; original address of Basic
  19.  
  20. èstart:    lxi    sp,stack
  21.  
  22. ; Define code length and start address
  23.  
  24.     lxi    h,buff        ; source for move
  25.     mov    c,m        ; get length of module
  26.     inx    h
  27.     mov    b,m
  28.     mov    a,b        ; anything there?
  29.     ora    c
  30.     jz    exit        ; ..no
  31.  
  32.     lxi    d,0feh
  33.     dad    d        ; start of code
  34.     xchg            ; put in DE
  35.     push    b        ; save count
  36.     push    b
  37.  
  38. ; Compute destination address in HL
  39.  
  40.     lhld    6        ; get bdos address
  41.     shld    buff+100h    ; insert in module
  42.     mvi    l,0        ; ensure we go to a page boundry
  43.     inr    b        ; convert length to pages
  44.     mov    a,h
  45.     sub    b
  46.     mov    h,a
  47. è
  48. ; Now move the code to the address in HL
  49.  
  50.     pop    b        ; restore byte count
  51.     push    h        ; save destination address
  52. movlp:    ldax    d        ; get byte of code
  53.     mov    m,a        ; move to new location
  54.     inx    h        ; step pointers
  55.     inx    d
  56.     dcx    b        ; and decrement counter
  57.     mov    a,c
  58.     ora    b        ; done?
  59.     jnz    movlp        ; ..no, loop
  60.  
  61.     pop    h        ; restore destination
  62.     shld    6        ; setup new bdos vector
  63.     xchg
  64.     pop    b        ; restore count
  65.  
  66. ; Now BC has the byte count, HL points to the first byte of the
  67. ; bit map, and DE has the destination address
  68.  
  69.     push    h        ; bit map address to top of stack
  70.     mov    h,d        ; (h) is relocated page offset
  71.  
  72. reclp:    mov    a,b        ; check if done
  73.     ora    c
  74. è    jz    exit        ; ..yes, go start up Basic
  75.     dcx    b        ; decrease count
  76.     mov    a,e        ; is DE address modulo 8 bytes?
  77.     ani    7        ;   if so - must get next map byte
  78.     jnz    rec2        ; ..no
  79.  
  80. ; Get next map byte via top of stack
  81.  
  82.     xthl            ; get current map pointer
  83.     mov    a,m        ; get byte into A
  84.     inx    h        ; point to next byte
  85.     xthl
  86.     mov    l,a        ; store in L
  87.  
  88. rec2:    mov    a,l        ; check next bit in byte
  89.     ral
  90.     mov    l,a        ; save for later
  91.     jnc    rec3        ; no relocation required
  92.  
  93. ; Add in the offset for a set bit 
  94.  
  95.     ldax    d        ; get byte
  96.     add    h        ; add offset
  97.     stax    d        ; store relocated byte back
  98. rec3:    inx    d        ; step to next byte in relocated
  99.     jmp    reclp        ;   code and around again
  100.  
  101. è; <stack> must occur on an 8 bit boundry
  102.  
  103.     org    ($ AND 0fff0h) + 10h
  104.  
  105. stack    equ    $
  106.     db    0
  107. buff:    dw    0    ; zero for no module case
  108.  
  109.     end
  110.