home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / math / huge1.asm < prev    next >
Assembly Source File  |  1994-02-15  |  2KB  |  143 lines

  1. ;Demonstrates the use of huge (normalised) pointers in assembler
  2. ;You can randomly access data accross segments
  3. ;Paul Carmichael 100014,1051
  4.  
  5.     .model compact    ;doesn't matter - small would work
  6.     .386
  7.  
  8.  
  9. paul    struct
  10.     db    4 dup(?)
  11. paul    ends    
  12.  
  13.  
  14.  
  15. get_npointerb    macro    segname,index,destpointer    ;get normalised pointer
  16.  
  17.     mov    eax,index
  18.     xor    esi,esi
  19.     mov    si,segname
  20.     shl    esi,4    ;full 20 bit address
  21.  
  22.     add    eax,esi    ;20 bit linear address
  23.     mov    esi,eax    ;copy
  24.     shr    esi,4    ;normalised segment address
  25.     and    eax,0fh    ;normalised offset
  26.     shl    esi,16
  27.     add    eax,esi    ;32 bit pointer
  28.     mov    destpointer,eax
  29.     endm
  30.  
  31.  
  32.  
  33.  
  34. sseg    segment para stack 'stack'
  35.     dw    256 dup(0)          ;allocate a stack
  36. sseg    ends
  37.  
  38. dseg    segment word public 'data'
  39.  
  40. dseg1    dw    ?    ;paragraph address of base of data
  41.  
  42. blob    dd    ?    ;storage for normalised 32 bit pointer
  43.  
  44. pauls_name    paul {'Paul'}
  45.  
  46. dseg    ends    
  47.  
  48.  
  49. cseg    segment byte public 'code'
  50.  
  51.     assume    cs:cseg,ds:dseg
  52.  
  53. main    proc    far
  54.     mov    bx,1000h
  55.     mov    dx,ds
  56.     add    bx,dx
  57.     mov    ah,4ah    ;make some memory available
  58.     int    21h
  59.  
  60.     mov    ax,dseg
  61.     mov    ds,ax      ;set up ds
  62.  
  63.     mov    bx,65536*2/16
  64.     mov    ah,48h
  65.     int    21h    ;allocate 128k
  66.     jc    quit
  67.     mov    dseg1,ax    ;save segment address of block
  68.  
  69.     call    fill_128    ;fill it with stuff
  70.  
  71.  
  72.     ;print 128k consecutive bytes to the screen...WOW!
  73.  
  74.  
  75.     mov    ecx,20000h    ;128k
  76.     xor    edi,edi    ;index
  77. nextchar:
  78.     get_npointerb dseg1,edi,blob       ;start point, index, pointer
  79.     push    ds
  80.     
  81.     lds    bx,blob        ;ds:bx points at data
  82.     mov    dl,byte ptr[bx]    ;pick up a byte
  83.     mov    ah,2
  84.     int    21h        ;print it
  85.  
  86.     pop    ds
  87.     inc    edi        ;increment index
  88.     dec    ecx
  89.     jnz    nextchar
  90.  
  91.     mov    ax,dseg1
  92.     mov    es,ax
  93.     mov    ah,49h        ;free the memory
  94.     int    21h
  95.  
  96.  
  97. quit:
  98.     mov    ax,4c00h
  99.     int    21h    ;quit to DOS
  100.  
  101. main    endp
  102.  
  103.  
  104.  
  105.  
  106. fill_128    proc    near
  107.     cld
  108.     mov    es,ax    ;ax contains dseg1 (the base of the data)
  109.     xor    di,di
  110.  
  111.      mov    cx,-1
  112.     mov    al,'A'    ;fill first seg with crap
  113.     rep    stosb    ;do 65535
  114.     stosb        ;= 64k
  115.  
  116.     mov    ax,dseg1
  117.     add    ax,4096    ;go to start of next 64k
  118.     mov    es,ax
  119.  
  120.     xor    di,di
  121.     mov    cx,8192
  122. next_line:
  123.     push    cx
  124.     mov    cx,sizeof pauls_name    ;fill 32k with something meaningful
  125.     mov    si,offset pauls_name
  126.     rep    movsb
  127.     pop    cx
  128.     loop    next_line
  129.  
  130.     mov    cx,32767
  131.     mov    al,'B'    ;fill rest with crap
  132.     rep    stosb
  133.     mov    al,'C'
  134.     stosb
  135.     ret
  136. fill_128    endp
  137.  
  138. cseg    ends
  139.  
  140.     end    main
  141.     
  142.  
  143.