home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / advmsdos / chap11 / extmem.asm next >
Encoding:
Assembly Source File  |  1988-10-01  |  4.0 KB  |  180 lines

  1.          title     EXTMEM --- get/put extended memory
  2.          page      55,132
  3.  
  4. ;
  5. ; EXTMEM.ASM --- Demonstration of access to
  6. ;                extended memory using ROM BIOS
  7. ;                Int 15H Function 87H
  8. ;
  9. ; Copyright (C) June 1988 Ray Duncan
  10. ;
  11. ; Build:   MASM EXTMEM;
  12. ;       LINK EXTMEM;
  13. ;
  14. ; Usage:   EXTMEM
  15.  
  16. stdin    equ    0        ; standard input device
  17. stdout    equ    1        ; standard output device    
  18. stderr    equ    2        ; standard error device
  19.  
  20. cr    equ    0dh        ; ASCII carriage return
  21. lf    equ    0ah        ; ASCII line feed
  22.  
  23.  
  24. DGROUP    group    _DATA,STACK    ; 'automatic data group'
  25.  
  26.  
  27. _DATA    segment    word public 'DATA'
  28.  
  29. bmdt    db    30h dup (0)    ; block move descriptor table    
  30.  
  31. buff1    db    80h dup ('?')    ; source buffer
  32. buff2    db    80h dup (0)    ; destination buffer
  33.  
  34. _DATA    ends
  35.  
  36.  
  37. STACK    segment    para stack 'STACK'
  38.  
  39.     dw    64 dup (?)
  40.  
  41. STACK    ends
  42.  
  43.  
  44. _TEXT    segment    word public 'CODE'
  45.  
  46.     assume    cs:_TEXT,ds:DGROUP,ss:STACK
  47.  
  48. main    proc    far           ; entry point from MS-DOS
  49.  
  50.     mov    ax,DGROUP    ; set DS = our data segment
  51.     mov    ds,ax
  52.     mov    es,ax
  53.  
  54.                 ; copy 'buff1' to extended
  55.                 ; memory address 100000H
  56.     mov    dx,10h        ; DX:AX = destination
  57.     mov    ax,0        ; extended mem. address
  58.     mov    bx,seg buff1    ; DS:BX = source conv.
  59.     mov    ds,bx        ; memory address
  60.     mov    bx,offset buff1
  61.     mov    cx,80h        ; CX = bytes to move
  62.     mov    si,seg bmdt    ; ES:SI = block move 
  63.     mov    es,si        ; descriptor table
  64.     mov    si,offset bmdt
  65.     call    putblk        ; request transfer
  66.  
  67.  
  68.                 ; fill buff2 from extended
  69.                 ; memory address 100000H
  70.     mov    dx,10h        ; DX:AX = source extended 
  71.     mov    ax,0        ; memory address
  72.     mov    bx,seg buff2    ; DS:BX = destination 
  73.     mov    ds,bx        ; conventional mem. address
  74.     mov    bx,offset buff2
  75.     mov    cx,80h        ; CX = bytes to move
  76.     mov    si,seg bmdt    ; ES:SI = block move
  77.     mov    es,si        ; descriptor table
  78.     mov    si,offset bmdt
  79.     call    getblk        ; request transfer
  80.  
  81.     mov    ax,4c00h    ; no error, terminate program 
  82.     int    21h        ; with return code = 0
  83.  
  84. main2:    mov    ax,4c01h    ; error, terminate program
  85.     int    21h        ; with return code = 1 
  86.  
  87. main    endp            ; end of main procedure
  88.  
  89.  
  90.  
  91.  
  92. getblk    proc    near        ; Transfer block from extended
  93.                 ;   memory to real memory
  94.                 ; Call with 
  95.                 ; DX:AX = linear 32-bit 
  96.                 ;         extended memory address
  97.                 ; DS:BX = segment and offset
  98.                 ;         destination address
  99.                 ; CX    = length in bytes
  100.                 ; ES:SI = block move descriptor table
  101.                 ; Returns
  102.                 ; AH    = 0 if transfer OK
  103.  
  104.     mov    es:[si+10h],cx    ; store length into descriptors
  105.     mov    es:[si+18h],cx 
  106.  
  107.                 ; store access rights bytes
  108.     mov    byte ptr es:[si+15h],93h
  109.     mov    byte ptr es:[si+1dh],93h
  110.  
  111.     mov    es:[si+12h],ax    ; source extended memory address
  112.     mov    es:[si+14h],dl
  113.  
  114.                 ; convert destination segment
  115.                 ; and offset to linear address
  116.     mov    ax,ds        ; segment * 16
  117.     mov    dx,16
  118.     mul    dx
  119.     add    ax,bx        ; + offset -> linear address
  120.     adc    dx,0
  121.  
  122.     mov    es:[si+1ah],ax    ; store destination address
  123.     mov    es:[si+1ch],dl
  124.  
  125.     shr    cx,1        ; convert length to words
  126.     mov    ah,87h        ; Int 15H Fxn 87h = block move
  127.     int    15h        ; transfer to ROM BIOS 
  128.  
  129.     ret            ; back to caller
  130.  
  131. getblk    endp
  132.  
  133.  
  134. putblk    proc    near        ; Transfer block from real 
  135.                 ;   memory to extended memory
  136.                 ; Call with 
  137.                 ; DX:AX = linear 32-bit
  138.                 ;         extended memory address
  139.                 ; DS:BX = segment and offset
  140.                 ;         source address
  141.                 ; CX    = length in bytes
  142.                 ; ES:SI = block move descriptor table
  143.                 ; Returns
  144.                 ; AH    = 0 if transfer OK
  145.  
  146.     mov    es:[si+10h],cx    ; store length into descriptors
  147.     mov    es:[si+18h],cx 
  148.  
  149.                 ; store access rights bytes
  150.     mov    byte ptr es:[si+15h],93h
  151.     mov    byte ptr es:[si+1dh],93h
  152.  
  153.     mov    es:[si+1ah],ax    ; store destination extended 
  154.     mov    es:[si+1ch],dl    ; memory address
  155.  
  156.                 ; convert source segment and
  157.                 ; offset to linear address
  158.     mov    ax,ds        ; segment * 16
  159.     mov    dx,16
  160.     mul    dx
  161.     add    ax,bx        ; + offset -> linear address
  162.     adc    dx,0
  163.  
  164.     mov    es:[si+12h],ax    ; store source address
  165.     mov    es:[si+14h],dl
  166.  
  167.     shr    cx,1        ; convert length to words
  168.     mov    ah,87h        ; Int 15H Fxn 87h = block move
  169.     int    15h        ; transfer to ROM BIOS 
  170.  
  171.     ret            ; back to caller
  172.  
  173. putblk    endp
  174.  
  175. _TEXT    ends
  176.  
  177.     end    main        ; defines program entry point
  178.  
  179.