2.

 

.

 

!!! !!!

 

, , . , . MS-DOS ( , Himem, EMM386, QEMM ..) Safe mode command prompt only Windows 9x. Windows 2000 ( Win NT/XP) , , .

 

1.

2.

3.

4.

5.

 

 

1.

 

-, , , , . (. 2). , :

 

  1. GDT.
  2. GDT.
  3. gdtr GDT.
  4. .
  5. .
  6. :

         ;

         ; ;

         ;

         ;

  1. .
  2. .
  3. MS-DOS .

 

(. ).

 

GDT

 

, GDT. . LDT , . .

GDT, :

 

 

2. :

 

Descr struc

Limit dw 0

Base_1 dw 0

Base_2 db 0

Atr db 0

Lim_atr db 0

Base_3 db 0

Ends

 

, GDT :

 

gdt_seg segment para

gdt_0 descr <0,0,0,0,0,0>

gdt_gdt_8 descr <0,0,0,0,0,0>

gdt_ldt_10 descr <0,0,0,0,0,0>

gdt_ds_18 descr <0,0,0,0,0,0>

gdt_es_vbf_20 descr <0,0,0,0,0,0>

gdt_ss_28 descr <0,0,0,0,0, 0>

gdt_cs_30 descr <0,0,0,0,0,0>

gdt_size=$-gdt_0-1 ; GDT

gdt_seg ends

 

GDT

 

limit .

 

base_1, base_2, base_3 32- . gdt_gdt_8 :

 

r ,

mov ax,gdt_seg ;

; 4

;20- gdt_seg:

shl eax,4

mov base_1,

rol eax,16 ;

mov base_2,al

 

, , load_addr:

 

load_addr macro descr,seg_addr,seg_size

mov descr.limit,seg_size

xor eax,eax

mov ax,seg_adr

shl eax,4

mov descr.base_1,ax

rol eax,16

mov descr.base_2,al

endm

 

.

atr - . . , . .

 

; 0, 4, 5, 6, 7 - ATR

; ( )

const equ 10010000b

 

; 1 - /

code_r_n equ 00000000b ; :

code_r_y equ 00000010b ; :

data_wm_n equ 00000000b ; : data_wm_y equ 00000010b ; :

; 2 -

code_n equ 00000000b ;

code_p equ 00000100b ;

_data equ 00000000b ;

_stack equ 00000100b ;

 

; 3

_code equ 00001000b ;

data_stk equ 00000000b ;

 

, , , gdt_gdt_8:

 

atr = const or data_wm_y or _data or data_stk

 

atr gdt_gdt_8 10010010 = 92h. , , : atr , ( , gdt_gdt_8 atr_gdt_gdt_8):

 

atr macro descr,bit1,bit2, bit3

atr&descr=const or bit1 or bit2 or bit3

endm

 

, gdt_gdt_8:

 

gdt_seg segment para

gdt_0 descr <0,0,0,0,0,0>

atr gdt_gdt_8,data_wm_y,_data,data_stk

gdt_gdt_8 descr <0,0,0,atr_gdt_gdt_8,0,0>

gdt_seg ends

 

lim_atr - , . , 0. ;

base_3 4- . , 20 , .

 

, : limit, base_1 base_2 atr.

 

gdtr

 

gdtr lgdt:

 

lgdt _48-_ (Load GDT register) - gdtr.

 

lgdt gdtr 6- , . , gdtr, lgdt.

(48 ) TASM dp df. GDT . . :

 

point struc

lim dw 0

adr dd 0

ends

 

data segment

point_gdt point <gdt_size,0>

;...

code segment

;...

xor eax,eax

mov ax,gdt_seg

shl eax,4

mov dword ptr point_gdt.adr,eax

lgdt pword point_gdt

 

 

, , , 18,2 , . : cli. , .

 

 

, . . , , PE r0. :

PE r0. : PE = 0, , PE = 1, ;

89h 15h BIOS. , .

 

r0 ( ), PE , :

 

mov eax,cr0

or eax,0001h

mov cr0,eax

 

mov .

89h 15h . , :

         ah = 89h;

         bl = irq0. irql...7 ;

         bh = irq8. irq9...f ;

         ds:si = GDT ;

         = ,

 

, GDT :

         0h ;

         8h GDT;

         10h LDT;

         18h , ds;

         20h , es;

         28h , ss;

         30h , cs;

         .

 

GDT , :

 

code segment

mov ah,89h

mov bl,20h

mov bh,28h

mov ax,gdt_seg

mov ds,ax

mov si,0

lea cx,protect

int 15h

protect:

;

 

 

, : cs:ip , . . cs , GDT. , cs , . . , cs , . . , cs i. eip\ip, cs eip\ip. , , , . , cs. :

 

ode segment

db 0eah ; jmp

dw offset protect ;

dw 30h ; GDT

protect:

;

mov ax,18h

mov ds,ax ;

mov ax,28h

mov ss,ax ;

mov ax,20h

mov es,ax ; :

;

 

 

, . . 64 . . , GDT. , . , , .

 

 

. , . , , . , - (. ).

 

 

, . , , , . , , :

         64 = 0ffffh;

         G = 0 ( ) ;

         10010010 = 92h;

         .

 

, , . . :

 

code segment

;...

;

; 0ffffh

mov gdt_ds_18.limit,0ffffh

; cs, ss, es, fs gs

; - , ds

mov ax,18

mov ds,ax

; ss, es, fs gs

; cs

; - jmp far

db 0eah

dw offset jump

dw 30h

jump:

;

 

 

, . , . , , .

 

 

r0 ( 386+). . :

 

mov eax,cr0

and al,0feh

mov cr0,eax

 

PE .

 

 

. :

 

;...

; cs

db 0eah

dw real_mode

dw code real_mode:

mov ax,data

mov ds,ax

mov ax,stk

mov ss,ax

 

 

. , : ) , , ) . , , .

 

2

 

. , , . ( ), . , . , , . - -, . , .

, , :

 

1.      IDT.

2.      .

3.      .

4.      i8259A.

5.      IDTR IDT.

6.      .

7.      .

 

, , . , :

 

1.      .

2.      .

3.      .

4.      .

5.      .

 

IDT

 

, , , 0 255. , ( ) 32 0...31. 32 0...17, 18...31 . IDT , - . , , IDT:

 

descr_idt struc

offs_1 dw 0 ;


sel dw 30 ; GDT

no_use db 0

type_attr db 8eh ; ,

; - 8fh

offs_2 dw 0;

ends

 

ID. , . , IDT .

 

idt_seg segment

rept 5

descr_idt <dummy,,,,>

endm

int05h descr_idt <int_05h,,,,>

rept 7

descr_idt <dummy_err,,,,>

endm

int0dh descr_idt <int_0dh,,,,>

rept 3

descr_idt <dummy,,,,>

endm

int11h descr_idt <dummy_err,,,,>

rept 14

descr_idt <dummy,,,,>

endm

int20h descr_idt <new_08h,,,,>

int21h descr_idt <sirena,38,,,>

rept 221

descr_idt <dummy,,,,>

endm

idt_seg ends

 

, . . dummy, . ; .

 

 

. , . , eip, cs eflags . :

 

1.      ( ).

2.      .

3.      , , . , , .

4.      2 ;

5.      iret.

 

, , 8. . , 5 13 (0Dh), 3 .

 

i8259

 

BIOS ( ). BIOS : 08h, 70h. , , IDT dummy. ? , . , , .

 

IDTR

 

GDT , ID. idtr. , , , . idtr point, gdtr. idtr lidt, :

 

lidt _48-_ (Load IDT register) idtr.

 

lidt idtr 6- , .

 

point struc

lim dw 0

adr dd 0

ends

data segment

point_idt point <idt_size,0>

data ends

code segment

xor eax,eax

mov ax,idt_seg

shl eax,4

mov dword ptr point_idt.adr,eax

lidt pword point_idt

code ends

 

. , . , , .

 

:

 

  1. 1
  2. 2
  3. mac.inc show.inc

 

.

 

3 Kernel

 

.

386+.

 

:

 

- 32-

-

-

- ( 0- 3- )

 

( ) .

.

 

 

TASM 3.1 ( , TASM 5.0, )

:

 

tasm /m2 /mx /o /t kernel.asm

tlink /3 /x kernel.obj

 

4

 

386+.

 

(PAGING NOPAGING) , PG CR0 "1" . ( ). : . - , . , .

 

( ) .

.

 

 

TASM 3.1 ( , TASM 5.0, )

:

 

tasm /m2 /mx /o /t paging.asm

tlink /3 /x paging.obj

 

tasm /m2 /mx /o /t nopaging.asm

tlink /3 /x nopaging.obj

 

5 V86

 

DOS x86 - V86 Mode. V86 , Command.com, DOS-.

 

:

 

- 32-

-

-

- TSS

- V86

- 8- V86

- - 87H 15H BIOS

- COMMAND.COM

- , , V86

 

( ) .

.

 

 

TASM 3.1 ( , TASM 5.0, )

:

 

tasm /m2 /mx /o /t v86.asm

tlink /3 /x v86.obj

 

1

 

;prog1.asm

.586P ; Pentium

.MODEL large

include mac.inc

;

descr STRUC

limit dw 0

base_1 dw 0

base_2 db 0

attr db 0

lim_atr db 0

base_3 db 0

ENDS

;

load_descr MACRO des,seg_addr,seg_size

mov des.limit,seg_size

xor eax,eax

mov ax,seg_addr

shl eax,4

mov des.base_1,ax

rol eax,16

mov des.base_2,al

ENDM

atr MACRO descr,bit1,bit2,bit3

;

;

atr_&descr=constp or bit1 or bit2 or bit3

ENDM

; gdtr

point STRUC

lim dw 0

adr dd 0

ENDS

;

; AR

; - 0, 4, 5, 6, 7

constp equ 10010000b

; 1

code_r_n equ 00010000b ; :

; ;

code_r_y equ 00000010b ; :

;

data_wm_n equ 00000000b ; :

;

data_wm_y equ 00000010b ; :

; ;

; 2

code_n equ 00000000b ;

code_p equ 00000100b ;

data_ equ 00000000b ;

stack_ equ 00000000b ;

; 3

code_ equ 00001000b ;

data_stk equ 00000000b ;

 

stk segment stack 'stack' use16

db 256 dup (0)

stk ends

;

gdt_seg segment para public 'data' use16

gdt_0 descr <0,0,0,0,0,0> ;

atr gdt_gdt_8,data_wm_y,data_,data_stk

; gdt

gdt_gdt_8 descr <0,0,0,atr_gdt_gdt_8,0,0>

;

gdt_ldt_10 descr <0,0,0,0,0,0>

atr gdt_ds_18,data_wm_y,data_,data_stk

;

gdt_ds_18 descr <0,0,0,atr_gdt_ds_18,0,0>

atr gdt_vbf_20,data_wm_y,data_,data_stk

gdt_es_vbf_20 descr <0,0,0,atr_gdt_vbf_20,0,0> ;

atr gdt_ss_28,data_wm_y,stack_,data_stk

gdt_ss_28 descr <0,0,0,atr_gdt_ss_28,0,0> ;

atr gdt_cs_30,code_r_y,code_n,code_

gdt_cs_30 descr <0,0,0,atr_gdt_cs_30,0,0> ;

gdt_size=$-gdt_0-1 ; GDT 1

GDT_SEG ENDS

;

data segment para public 'data' use16 ;

point_gdt point <gdt_size,0>

hello db " "

hel_size=$-hello

tonelow dw 2651 ; 450

cnt db 0 ;

temp dw ? ;

data_size=$-point_gdt-1

data ends

code segment byte public 'code' use16

; 16-

assume cs:code,ss:stk

main proc

mov ax,stk

mov ss,ax

;

assume ds:gdt_seg

mov ax,gdt_seg

mov ds,ax

load_descr gdt_gdt_8,GDT_SEG,gdt_size

load_descr gdt_ds_18,DATA,data_size

load_descr gdt_es_vbf_20,0b800h,3999

load_descr gdt_ss_28,STK,255

load_descr gdt_cs_30,CODE,0ffffh ;code_size

assume ds:data

mov ax,data

mov ds,ax

; gdtr

xor eax,eax

mov ax,gdt_seg

shl eax,4

mov point_gdt.adr,eax

lgdt point_gdt

;

cli

mov al,80h

out 70h,al

;

mov eax,cr0

or al,1

mov cr0,eax

;

db 0eah ; jmp

dw offset protect ;

;

dw 30h ;

; GDT

protect:

;

mov ax,18h

mov ds,ax

mov ax,20h

mov es,ax

mov ax,28h

mov ss,ax

; :

;

mov cx,hel_size ;

mov si,offset hello ;

mov di,1640 ;

mov ah,07h ;

outstr1:

mov al,[si]

mov es:[di],ax

inc si

inc di

inc di

loop outstr1

;

go:

; 110110110b (06h):

; 43h -

mov ax,0B06h

out 43h,ax ; 43h

in al,61h ; 61h al

or al,3 ; -

out 61h,al ; 61h

mov cx,2083 ;

musicup:

; ax 1193000/2651 = 450 ,

; 1193000-

mov ax,tonelow

out 42h,al ;al 42h

mov al,ah ; al ah

out 42h,al ; ax (ah) 42h

add tonelow,1 ;

delay 1 ; 1

mov dx,tonelow ; dx

mov temp,dx ;temp -

loop musicup ;

mov cx,2083

musicdown:

mov ax,temp ; ax

out 42h,al ; ax (al) 42h

mov al,ah ; al ah

out 42h,al ; 42h ax (ah)

sub temp,1 ;

delay 1 ; 1

loop musicdown ;

nosound:

in al,61h ; 61h al

; -

and al,0FCh

out 61h,al ; 61h

mov dx,2651 ;

mov tonelow,dx

; -

inc cnt

cmp cnt,5 ;5

jne go ; - go

;

assume ds:gdt_seg

mov ax,8h

mov ds,ax

mov gdt_ds_18.limit,0ffffh

mov gdt_es_vbf_20.limit,0ffffh

mov gdt_ss_28.limit,0ffffh

mov gdt_cs_30.limit,0ffffh

assume ds:data

;

mov ax,18h

mov ds,ax

mov ax,20h

mov es,ax

mov ax,28h

mov ss,ax

db 0eah

dw offset jump

dw 30h

jump:

mov eax,cr0

and al,0feh

mov cr0,eax

db 0eah

dw offset r_mode

dw code

r_mode:

mov ax,data

mov ds,ax

mov ax,stk

mov ss,ax

;

sti

xor al,al

out 70h,al

; ()

mov ax,4c00h

int 21h

main endp

code ends

end main

 

 

2

 

;prog2.asm

.386P ; i386

.MODEL large

; al, ah, ax eax

include show.inc

include mac.inc

;

descr STRUC

limit dw 0

base_1 dw 0

base_2 db 0

attr db 0

lim_atr db 0

base_3 db 0

ENDS

;

load_descr MACRO des,seg_addr,seg_size

mov des.limit,seg_size

xor eax,eax

mov ax,seg_addr

shl eax,4

mov des.base_1,ax

rol eax,16

mov des.base_2,al

ENDM

atr MACRO descr,bit1,bit2,bit3

atr_&descr=constp or bit1 or bit2 or bit3

ENDM

; gdtr idtr

point STRUC

lim dw 0

adr dd 0

ENDS

; idt

descr_idt STRUC

offs_1 dw 0

sel dw 30h ; GDT

no_use db 0

type_attr db 8eh ;

offs_2 dw 0

ENDS

 

;

constp equ 10010000b

code_r_n equ 00010000b

code_r_y equ 00000010b

data_wm_n equ 00000000b

data_wm_y equ 00000010b

code_n equ 00000000b

code_p equ 00000100b

data_ equ 00000000b

stack_ equ 00000000b

code_ equ 00001000b

data_stk equ 00000000b

 

stk segment stack 'stack'

db 256 dup (0)

stk ends

 

;

gdt_seg segment para public 'data' use16

gdt_0 descr <0,0,0,0,0,0>

atr gdt_gdt_8,data_wm_y,data_,data_stk

; GDT

gdt_gdt_8 descr <0,0,0,atr_gdt_gdt_8,0,0>

gdt_ldt_10 descr <0,0,0,0,0,0> ;

atr gdt_ds_18,data_wm_y,data_,data_stk

;

gdt_ds_18 descr <0,0,0,atr_gdt_ds_18,0,0>

atr gdt_vbf_20,data_wm_y,data_,data_stk

gdt_es_vbf_20 descr <0,0,0,atr_gdt_vbf_20,0,0> ;

atr gdt_ss_28,data_wm_y,stack_,data_stk

gdt_ss_28 descr <0,0,0, atr_gdt_ss_28,0,0> ;

atr gdt_cs_30,code_r_y,code_n,code_

gdt_cs_30 descr <0,0,0,atr_gdt_cs_30,0,0> ;

atr gdt_sirena_38,code_r_y,code_n,code_

gdt_sirena_38 descr <0,0,0,atr_gdt_sirena_38,0,0>

gdt_size=$-gdt_0-1 ; GDT 1

gdt_seg ends

 

idt_seg segment para public 'data' use16

int00h descr_idt <dummy,,,,>

REPT 2

descr_idt <dummy,,,,>

ENDM

int03h descr_idt <int_03h,,,,>

descr_idt <dummy,,,,>

int05h descr_idt <int_05h,,,,>

REPT 7

descr_idt <dummy_err,,,,>

ENDM

int0dh descr_idt <int_0dh,,,,>

REPT 3

descr_idt <dummy,,,,>

ENDM

int11h descr_idt <dummy_err,,,,>

REPT 14

descr_idt <dummy,,,,>

ENDM

int20h descr_idt <new_08h,,,,>

int21h descr_idt <sirena,38h,,,>

REPT 222

descr_idt <dummy,,,,>

ENDM

idt_size=$-int00h-1

idt_seg ends

 

;

data segment para public 'data' use16 ;

point_gdt point <gdt_size,0>

point_idt point <idt_size,0>

char db '0'

maskf db 07h

position dw 2000

tonelow dw 2651 ; 450

cnt db 0 ;

temp dw ? ;

min_index dw 0

max_index dw 99

data_size=$-point_gdt-1

data ends

 

SOUND SEGMENT byte private use16

assume cs:SOUND,ds:DATA,ss:STK

sirena PROC ;

push ds

push ax

push cx

push dx

go:

; 10110110b(06h) ( 43h)

mov al,0B6h

out 43h,al

in al,61h ; 61h al

or al,3 ; 61h

out 61h,al

mov cx,2083 ;

musicup:

; ax

mov ax,tonelow

out 42h,al ; 42h ax :al

xchg al,ah ; al ah

out 42h,al ; 42h ax:ah

add tonelow,1 ;

delay 1 ; 1

mov dx,tonelow ; dx

mov temp,dx ;temp -

loop musicup ;

mov cx,2083 ;

musicdown:

mov ax,temp ; ax

out 42h,al ; 42h ax :al

mov al,ah ; al ah

out 42h,al; 42h ax :ah

sub temp,1 ;

delay 1 ; 1

loop musicdown ;

nosound:

in al,61h ; 61h AL

and al,0FCh ;

out 61h,al ; 61h

mov dx,2651 ;

mov tonelow,dx

inc cnt ; ,

;

cmp cnt,5 ;5 ?

 

jne go ; - go

pop dx

pop cx

pop ax

pop ds

mov bp,sp

mov eax,[bp]

show eax,0

mov eax,[bp+4]

show eax,160

mov eax,[bp+8]

show eax,320

db 66h

iret

endp

sound_size=$-sirena-1

sound ends

 

code segment byte public 'code' use16

; 16-

assume cs:code,ss:stk

dummy proc ;

mov ax,0ffffh

db 66h

iret

endp

dummy_err proc ;

pop eax ;

db 66h

iret

endp

int_03h proc

; ,

; eip

pop eax

show eax,0

push eax

db 66h

iret

endp

int_05h proc ; 5- - bound

mov al,5

mov ah,al

mov si,2

db 66h

iret

endp

int_0dh proc

pop eax ;

sub bx,4 ;

db 66h ;

iret

endp

new_08h proc ;

assume ds:data

push ds

push es

push ax

push bx

mov ax,20h

mov es,ax

scr:

mov al,char

mov ah,maskf

mov bx,position

mov es:[bx],ax

add bx,2

mov position,bx

inc char

pop bx

pop ax

pop es

pop ds

mov al,20h

out 20h,al

db 66h

iret

endp

new_8259a proc

; al -

;

push ax

mov al,00010001b

out 20h,al ;ICW1 20h

jmp $+2

jmp $+2 ;,

pop ax

out 21h,al ;ICW2 20h -

jmp $+2

jmp $+2 ;,

;

mov al,00000100b

out 21h,al ;ICW3 -

; 2 (. . 15.1)

jmp $+2

jmp $+2 ;,

;

mov al,00000001b

out 21h,al ;ICW4 - EOI

ret

endp

main proc

mov ax,stk

mov ss,ax

;

assume ds:GDT_SEG

mov ax,GDT_SEG

mov ds,ax

load_descr gdt_gdt_8,GDT_SEG,gdt_size

load_descr gdt_ds_18,DATA,data_size

load_descr gdt_es_vbf_20,0b800h,3999

load_descr gdt_ss_28,STK,255

load_descr gdt_cs_30,CODE,code_size

load_descr gdt_sirena_38,SOUND,sound_size

assume ds:data

mov ax,data

mov ds,ax

; gdtr

xor eax,eax

mov ax,GDT_SEG

shl eax,4

mov point_gdt.adr,eax

lgdt point_gdt

;

cli

mov al,80h

out 70h,al

mov al,20h ;

call new_8259A

; idtr

xor eax,eax

mov ax,IDT_SEG

shl eax,4

mov point_idt.adr,eax

lidt point_idt

;

mov eax,cr0

or al,1

mov cr0,eax

;

db 0eah ; jmp

dw offset protect ;

;

dw 30h ; GDT

protect:

;

mov ax,18h

mov ds,ax

mov ax,20h

mov es,ax

mov ax,28h

mov ss,ax

; :

; ,

sti

delay 3500

cli

;

; ( ): 5 13

mov si,130

bound si,dword ptr min_index

mov bx,data_size

mov ax,[bx]

; - 3:

int 3

;

;

int 21h

;

;

;

mov al,08h

call new_8259A

;

assume ds:GDT_SEG

mov ax,8h

mov ds,ax

mov gdt_ds_18.limit,0ffffh

mov gdt_es_vbf_20.limit,0ffffh

mov gdt_ss_28.limit,0ffffh

mov gdt_cs_30.limit,0ffffh

assume ds:DATA

;

mov ax,18h

mov ds,ax

mov ax,20h

mov es,ax

mov ax,28h

mov ss,ax

db 0eah

dw offset jump

dw 30h

jump: mov eax,cr0

and al,0feh

mov cr0,eax

db 0eah

dw offset r_mode

dw CODE

r_mode:

mov ax,DATA

mov ds,ax

mov ax,STK

mov ss,ax

mov ax,3ffh

mov point_idt.lim,ax

xor eax,eax

mov point_idt.adr,eax

lidt point_idt

;

sti

xor al,al

out 70h,al

; ()

mov ax,4C00h

int 21h

main ENDP

code_size=$-dummy

code ends

end main

 

 

mac.inc

 

;mac.inc

GetStr macro Buf,MaxLen

local m,TmpBuf

; ( 0ah int 21h)

; :

;Buf -

;MaxLen -

; - Buf

;al -

jmp m

TmpBuf label byte ; 0ah (int 21h)

rept MaxLen+3 ;. -

db ' '

endm

m:

SaveReg <ds,es,dx,cx>

xor cx,cx

mov cs:TmpBuf,MaxLen+1

mov ah,0ah

push ds

pop es

push cs

pop ds

lea dx,cs:TmpBuf

int 21h

mov al,cs:TmpBuf+1

; TmpBuf Buf ( ):

mov cl,al ; al

lea si,cs:TmpBuf+2 ; - ds:si

lea di,buf ; - es:di

rep movsb

LoadReg <cx,dx,es,ds>

endm

 

mov_string macro dest,src,len

;

; : - - src, - - dest

; ds ( ) es ( )

;

mov cx,len

lea si,src

lea di,dest

rep movsb

endm

 

null_string macro dest,len

local m,Z_String

;

; :

;dest -

;len -

jmp m

Z_String label byte ;

rept len

db ' '

endm

m:

SaveReg <ds,es,cx,si,di>

mov cx,len

push ds

pop es ; dest () - es:di

push cs

pop ds ; Z_String () - ds:si

lea si,cs:Z_String

lea di,dest

rep movsb

LoadReg <di,si,cx,es,ds>

endm

OutStr macro str

; .

; - .

; '$'.

; - .

SaveReg <ax,dx>

mov ah,09h

lea dx,str

int 21h

LoadReg <dx,ax>

endm

 

GetChar macro

; .

; - al .

mov ah,01h

int 21h

endm

 

OutChar macro

; .

; - dl .

push ax

mov ah,02h

int 21h

pop ax

endm

 

SaveReg macro RegList

; RegList

; ,

; - <ax,bx,cx>

irp reg,<RegList>

push reg

endm

endm

 

LoadReg macro RegList

; RegList

; ,

; - <ax,bx,cx>

irp reg,<RegList>

pop reg

endm

endm

 

clear_r macro rg

; rg

xor rg,rg

endm

 

conv_16_2 macro

;

; al

sub dl,30h

cmp dl,9h

jle $+5

sub dl,7h

endm

 

init_ds macro

; ds

mov ax,data

mov ds,ax

xor ax,ax

endm

 

delay macro time

local ext,iter

; . - ( ).

push cx

mov cx,time

ext: push cx

mov cx,5000 ; , .

iter: loop iter

pop cx

loop ext

pop cx

endm

 

_Exit macro

; .

mov ax,4c00h

int 21h

endm

 

 

show.inc

 

;;show.inc

;; al, ah, ax, eax

;; :

;;arg_n - al,ah,ax,eax

;;n_poz - , - 1000

Show MACRO arg_n,n_poz:=<1000>

LOCAL main_part,disp,pause,template,VideoBuffer,p_mode,m1,m2

;; ,

;;

jmp main_part

;;

FALSE equ 0 ;;

TRUE equ 0ffffh ;;

?reg8bit=false ;; , ah al

?reg16bit=false ;; , ax

?reg32bit=false ;; , eax

;;- xlat

template db '0123456789ABCDEF'

;; -

VideoBuffer dw 0b800h

 

main_part: ;;

;; :

;;eax, ebx, ecx, edx, edi, ds, es

push eax

push ebx

push ecx

push edx

push edi

push ds

push es

push cs

pop ds

;; bx - - ( xlat)

lea bx,cs:template

xor cx,cx ; cx

;; ,

;;

IFIDNI <al>,<&arg_n> ;; =al AL,

?reg8bit=TRUE ;; 8-

mov ah,al

ENDIF

;; al AL

IFIDNI <ah>,<&arg_n> ;; =ah AH,

?reg8bit=TRUE ;; 8-

ENDIF

;; AH ah

IFIDNI <ax>,<&arg_n> ;; ax AX,

?reg16bit=TRUE ;; 16-

ENDIF

;; ah, AH ,ax AX

IFIDNI <eax>,<&arg_n> ;; eax EAX,

?reg32bit=TRUE ;; 32-

ENDIF

;; al, ah, ax, eax

IF (?reg8bit) ;; al ah

push eax

and ah,0f0h ;; ah

shr ax,12 ;; (16-4=12)

xlat ;; -

;; al edi

mov di,ax

shl di,8

inc cx

pop eax

and ax,0f00h ;; ah

shr ax,8 ;; (16-(4+4)=8)

xlat ;; -

or di,ax ;; di

shl edi,16

inc cx

ENDIF

IF (?reg16bit) ;; ax ax

;; ax

push eax

;; ax

and ax,0f000h

shr ax,12 ;; (16-4=12)

xlat ;; -

;; al

;; edi

mov di,ax

shl edi,8

inc cx

pop eax

push eax

;; ax

and ax,0f00h

shr ax,8 ;; (16-(4+4)=8)

xlat ;; -

;;

;; edi

or di,ax

shl edi,8

inc cx

pop eax

push eax

and ax,0f0h ;; ax

shr ax,4 ;; (16-(4+4+4)=4)

xlat ;; -

or di,ax ;; edi

shl edi,8

inc cx

pop eax

and ax,0fh ;; ax

xlat ;; -

or di,ax ;; edi

inc cx

ENDIF

IF (?reg32bit) ;; eax EAX

;; eax

push eax

;; eax

and eax,0f0000000h

shr eax,28 ;; (32-4=28)

xlat ;; -

;; al

;; edx

mov dh,al

shl edx,8

pop eax

push eax

inc cx

pop eax

push eax

;; eax

and eax,0f000000h

shr eax,24 ;; (32-(4+4)=24)

xlat ;; -

;; al

;; edx

mov dh,al

shl edx,8

inc cx

pop eax

push eax

and eax,0f00000h

shr eax,20

xlat

mov dh,al

inc cx

pop eax

push eax

and eax,0f0000h

shr eax,16

xlat

mov dl,al

inc cx

pop eax

push eax

and eax,0f000h

shr eax,12

xlat

or di,ax

shl edi,8

inc cx

pop eax

push eax

and eax,0f00h

shr eax,8

xlat

or di,ax

shl edi,8

pop eax

push eax

inc cx

and eax,0f0h

shr eax,4

xlat

or di,ax

shl edi,8

inc cx

pop eax

push eax

and eax,0fh

xlat

or di,ax

inc cx

ENDIF

;;

;; edx:ebx, cx

;;

mov eax,cr0

test eax,00000001h

jnz p_mode

;;

;; es

mov ax,cs:VideoBuffer

mov es,ax

p_mode:

;;

;; cx

cld ;; - stosw

xchg edi,ebx

mov di,n_poz ;;

;;

disp:

cmp ecx,4

jle m1 ;, ecx<=4

shld eax,edx,8

shl edx,8

jmp m2

m1:

shld eax,ebx,8

shl ebx,8

m2:

mov ah,71h ;;-

stosw ;; ax

;; es:di ()

loop disp ;; cx

mov cx,65535 ;;

pause: loop pause

;;/

;;

pop es

pop ds

pop edi

pop edx

pop ecx

pop ebx

pop eax

ENDM