home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
assemblr
/
library
/
math
/
huge1.asm
< prev
next >
Wrap
Assembly Source File
|
1994-02-15
|
2KB
|
143 lines
;Demonstrates the use of huge (normalised) pointers in assembler
;You can randomly access data accross segments
;Paul Carmichael 100014,1051
.model compact ;doesn't matter - small would work
.386
paul struct
db 4 dup(?)
paul ends
get_npointerb macro segname,index,destpointer ;get normalised pointer
mov eax,index
xor esi,esi
mov si,segname
shl esi,4 ;full 20 bit address
add eax,esi ;20 bit linear address
mov esi,eax ;copy
shr esi,4 ;normalised segment address
and eax,0fh ;normalised offset
shl esi,16
add eax,esi ;32 bit pointer
mov destpointer,eax
endm
sseg segment para stack 'stack'
dw 256 dup(0) ;allocate a stack
sseg ends
dseg segment word public 'data'
dseg1 dw ? ;paragraph address of base of data
blob dd ? ;storage for normalised 32 bit pointer
pauls_name paul {'Paul'}
dseg ends
cseg segment byte public 'code'
assume cs:cseg,ds:dseg
main proc far
mov bx,1000h
mov dx,ds
add bx,dx
mov ah,4ah ;make some memory available
int 21h
mov ax,dseg
mov ds,ax ;set up ds
mov bx,65536*2/16
mov ah,48h
int 21h ;allocate 128k
jc quit
mov dseg1,ax ;save segment address of block
call fill_128 ;fill it with stuff
;print 128k consecutive bytes to the screen...WOW!
mov ecx,20000h ;128k
xor edi,edi ;index
nextchar:
get_npointerb dseg1,edi,blob ;start point, index, pointer
push ds
lds bx,blob ;ds:bx points at data
mov dl,byte ptr[bx] ;pick up a byte
mov ah,2
int 21h ;print it
pop ds
inc edi ;increment index
dec ecx
jnz nextchar
mov ax,dseg1
mov es,ax
mov ah,49h ;free the memory
int 21h
quit:
mov ax,4c00h
int 21h ;quit to DOS
main endp
fill_128 proc near
cld
mov es,ax ;ax contains dseg1 (the base of the data)
xor di,di
mov cx,-1
mov al,'A' ;fill first seg with crap
rep stosb ;do 65535
stosb ;= 64k
mov ax,dseg1
add ax,4096 ;go to start of next 64k
mov es,ax
xor di,di
mov cx,8192
next_line:
push cx
mov cx,sizeof pauls_name ;fill 32k with something meaningful
mov si,offset pauls_name
rep movsb
pop cx
loop next_line
mov cx,32767
mov al,'B' ;fill rest with crap
rep stosb
mov al,'C'
stosb
ret
fill_128 endp
cseg ends
end main