home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / pmode / hello0.asm next >
Encoding:
Assembly Source File  |  1997-10-19  |  3.0 KB  |  134 lines

  1. ; hello0.asm : scrive un messaggio nella memoria video
  2. ;
  3. ; primo metodo : il descrittore e` creato manualmente
  4. ;
  5. ;
  6.     BITS 16
  7.         SECTION .text
  8.     ORG    0x100
  9.  
  10.         jmp    start
  11.  
  12.         err_dpmi   db 'nessun DPMI in memoria.$'
  13.     err_memory db 'memoria insufficiente.$'
  14.         err_pmode  db 'errore entrando in modo protetto.$'
  15.  
  16.         err_pm     db 'errore DPMI.$'
  17.         msg_hello  db 'Hello, world! (0)'
  18.  
  19.         endl       db 13,10,'$'
  20.         pm_ptr       dd 0
  21.  
  22.         descriptor              ; descrittore
  23.                dw 3999    ; limite  4000 caratteri
  24.                    dw 0x8000    ; base 0xB8000 (bit 0..15)
  25.                    db 0x0b      ; base 0xb8000 (bit 16..23)
  26.                    db 0xf2    ; P=1 DPL=3 W=1 (descrittore dati)
  27.                    db 0        ; 0 per compatibilita` col 286
  28.                    db 0        ; base 0xb8000 (bit 24..31)
  29.  
  30.  
  31. write_exit:
  32.     mov    ah,0x9
  33.         int    21h
  34.         mov    dx,endl
  35.         int    21h
  36.         mov    al,1
  37.  
  38. exit:
  39.     mov    ah,4ch
  40.         int    21h
  41.  
  42. start:
  43.         add    bx,0x1000
  44.     mov    ah,0x4a
  45.         int    21h      ; riserva 64K di memoria per questo programma
  46.  
  47.         ;
  48.         ; controllo presenza DPMI server
  49.         ;
  50.         mov    ax,1687h
  51.         int    2fh
  52.         test    ax,ax
  53.         mov    dx,err_dpmi
  54.         jnz    write_exit
  55.  
  56.         mov    [pm_ptr+2],es    ; memorizzo l'indirizzo usato per
  57.         mov    [pm_ptr],di     ; entrare in modo protetto
  58.  
  59.         test    si,si
  60.         jz    .go
  61.  
  62.         ; SI contiene i paragrafi di memoria che bisogna allocare
  63.     mov    bx,si
  64.     mov    ah,48h
  65.     int    21h
  66.     mov    dx,err_memory
  67.     jc    write_exit
  68.     mov    es,ax
  69.  
  70. .go
  71.     ; pongo ax = 0, indica modo protetto a 16 bit
  72.     xor    ax,ax
  73.         call    word far [pm_ptr]
  74.         mov    dx,err_pmode
  75.         ;
  76.         ; se c'e` un errore siamo ancora in modo reale,
  77.         ; percio` scrivi un messaggio di errore
  78.         jc    write_exit
  79.  
  80.         ; ----- ora siamo in modo protetto ------
  81.         ;
  82.         ; tutti i registri (tranne ES) hanno la stessa base
  83.         ; di prima, percio` e` possibile utilizzare le stesse
  84.         ; variabili
  85.         ;
  86.         ; ES contiene il selettore che punta al PSP del programma
  87.  
  88.  
  89.         ; richiedo un descrittore nella LDT
  90.         ; il decrittore viene creato di tipo dati con base e limite 0
  91.         mov    ax,0
  92.         mov    cx,1
  93.         int    31h
  94.         mov    dx,err_pm
  95.         jc    write_exit
  96.  
  97.         mov    si,ax        ; salvo in SI il selettore
  98.  
  99.         ;
  100.         ; copio il descrittore nella LDT
  101.         ;
  102.  
  103.         mov    bx,ax
  104.         mov    ax,0ch
  105.         mov    di,descriptor
  106.         push    ds
  107.         pop    es
  108.         int    31h
  109.         mov    dx,err_pm
  110.         jc    write_exit
  111.  
  112.         ;
  113.         ; scrivo la stringa nella memoria video
  114.         ;
  115.  
  116.         mov    es,si        ; in es il selettore appena creato
  117.         xor    di,di
  118.         mov    ah,4fh
  119.         mov    cx,17
  120.         mov    si,msg_hello
  121. .next                           ; scrivi la stringa
  122.         lodsb
  123.         stosw
  124.         loop    .next
  125.  
  126.  
  127.  
  128.         mov    al,0
  129.         jmp    exit
  130.  
  131.  
  132.  
  133.  
  134.