<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">         ;ä»£ç&nbsp;æ¸…å•8-2
         ;æ–‡ä»¶åï¼šc08.asm
         ;æ–‡ä»¶è¯´æ˜Žï¼šç”¨æˆ·ç¨‹åº 
         ;åˆ›å»ºæ—¥æœŸï¼š2011-5-5 18:17

;===============================================================================
SECTION header vstart=0                     ;å®šä¹‰ç”¨æˆ·ç¨‹åºå¤´éƒ¨æ®µ 
    program_length  dd program_end          ;ç¨‹åºæ€»é•¿åº¦[0x00]

    ;ç”¨æˆ·ç¨‹åºå…¥å£ç‚¹
    code_entry      dw start                ;åç§»åœ°å€[0x04]
                    dd section.code_1.start ;æ®µåœ°å€[0x06] 

    realloc_tbl_len dw (header_end-code_1_segment)/4
                                            ;æ®µé‡å®šä½è¡¨é¡¹ä¸ªæ•°[0x0a]

    ;æ®µé‡å®šä½è¡¨           
    code_1_segment  dd section.code_1.start ;[0x0c]
    code_2_segment  dd section.code_2.start ;[0x10]
    data_1_segment  dd section.data_1.start ;[0x14]
    data_2_segment  dd section.data_2.start ;[0x18]
    stack_segment   dd section.stack.start  ;[0x1c]

    header_end:                

;===============================================================================
SECTION code_1 align=16 vstart=0         ;å®šä¹‰ä»£ç&nbsp;æ®µ1ï¼ˆ16å­—èŠ‚å¯¹é½ï¼‰ 
put_string:                              ;æ˜¾ç¤ºä¸²(0ç»“å°¾)ã€‚
                                         ;è¾“å…¥ï¼šDS:BX=ä¸²åœ°å€
         mov cl,[bx]
         or cl,cl                        ;cl=0 ?
         jz .exit                        ;æ˜¯çš„ï¼Œè¿”å›žä¸»ç¨‹åº 
         call put_char
         inc bx                          ;ä¸‹ä¸€ä¸ªå­—ç¬¦ 
         jmp put_string

   .exit:
         ret

;-------------------------------------------------------------------------------
put_char:                                ;æ˜¾ç¤ºä¸€ä¸ªå­—ç¬¦
                                         ;è¾“å…¥ï¼šcl=å­—ç¬¦ascii
         push ax
         push bx
         push cx
         push dx
         push ds
         push es

         ;ä»¥ä¸‹å–å½“å‰å…‰æ&nbsp;‡ä½ç½®
         mov dx,0x3d4
         mov al,0x0e
         out dx,al
         mov dx,0x3d5
         in al,dx                        ;é«˜8ä½ 
         mov ah,al

         mov dx,0x3d4
         mov al,0x0f
         out dx,al
         mov dx,0x3d5
         in al,dx                        ;ä½Ž8ä½ 
         mov bx,ax                       ;BX=ä»£è¡¨å…‰æ&nbsp;‡ä½ç½®çš„16ä½æ•°

         cmp cl,0x0d                     ;å›žè½¦ç¬¦ï¼Ÿ
         jnz .put_0a                     ;ä¸æ˜¯ã€‚çœ‹çœ‹æ˜¯ä¸æ˜¯æ¢è¡Œç­‰å­—ç¬¦ 
         mov ax,bx                       ;æ­¤å¥ç•¥æ˜¾å¤šä½™ï¼Œä½†åŽ»æŽ‰åŽè¿˜å¾—æ”¹ä¹¦ï¼Œéº»çƒ¦ 
         mov bl,80                       
         div bl
         mul bl
         mov bx,ax
         jmp .set_cursor

 .put_0a:
         cmp cl,0x0a                     ;æ¢è¡Œç¬¦ï¼Ÿ
         jnz .put_other                  ;ä¸æ˜¯ï¼Œé‚£å°±æ­£å¸¸æ˜¾ç¤ºå­—ç¬¦ 
         add bx,80
         jmp .roll_screen

 .put_other:                             ;æ­£å¸¸æ˜¾ç¤ºå­—ç¬¦
         mov ax,0xb800
         mov es,ax
         shl bx,1
         mov [es:bx],cl

         ;ä»¥ä¸‹å°†å…‰æ&nbsp;‡ä½ç½®æŽ¨è¿›ä¸€ä¸ªå­—ç¬¦
         shr bx,1
         add bx,1

 .roll_screen:
         cmp bx,2000                     ;å…‰æ&nbsp;‡è¶…å‡ºå±å¹•ï¼Ÿæ»šå±
         jl .set_cursor

         mov ax,0xb800
         mov ds,ax
         mov es,ax
         cld
         mov si,0xa0
         mov di,0x00
         mov cx,1920
         rep movsw
         mov bx,3840                     ;æ¸…é™¤å±å¹•æœ€åº•ä¸€è¡Œ
         mov cx,80
 .cls:
         mov word[es:bx],0x0720          ; space
         add bx,2
         loop .cls

         mov bx,1920

 .set_cursor:
         mov dx,0x3d4
         mov al,0x0e
         out dx,al
         mov dx,0x3d5
         mov al,bh
         out dx,al
         mov dx,0x3d4
         mov al,0x0f
         out dx,al
         mov dx,0x3d5
         mov al,bl
         out dx,al

         pop es
         pop ds
         pop dx
         pop cx
         pop bx
         pop ax

         ret

;----------------------------------  ç”¨æˆ·ç¨‹åºå…¥å£ --------------------------------------------
  start:
         ;åˆå§‹æ‰§è¡Œæ—¶ï¼ŒDSå’ŒESæŒ‡å‘ç”¨æˆ·ç¨‹åºå¤´éƒ¨æ®µ
         mov ax,[stack_segment]           ;è®¾ç½®åˆ°ç”¨æˆ·ç¨‹åºè‡ªå·±çš„å&nbsp;†æ&nbsp;ˆ 
         mov ss,ax
         mov sp,stack_end

         mov ax,[data_1_segment]          ;è®¾ç½®åˆ°ç”¨æˆ·ç¨‹åºè‡ªå·±çš„æ•°æ®æ®µ
         mov ds,ax

         mov bx,msg0
         call put_string                  ;æ˜¾ç¤ºç¬¬ä¸€æ®µä¿¡æ¯ 

         push word [es:code_2_segment]
         mov ax,begin
         push ax                          ;å¯ä»¥ç›´æŽ¥push begin,80386+

         retf                             ;è½¬ç§»åˆ°ä»£ç&nbsp;æ®µ2æ‰§è¡Œ 

  continue:
         mov ax,[es:data_2_segment]       ;æ®µå¯„å­˜å™¨DSåˆ‡æ¢åˆ°æ•°æ®æ®µ2 
         mov ds,ax

         mov bx,msg1
         call put_string                  ;æ˜¾ç¤ºç¬¬äºŒæ®µä¿¡æ¯ 

         jmp $ 

;===============================================================================
SECTION code_2 align=16 vstart=0          ;å®šä¹‰ä»£ç&nbsp;æ®µ2ï¼ˆ16å­—èŠ‚å¯¹é½ï¼‰

  begin:
         push word [es:code_1_segment]
         mov ax,continue
         push ax                          ;å¯ä»¥ç›´æŽ¥push continue,80386+

         retf                             ;è½¬ç§»åˆ°ä»£ç&nbsp;æ®µ1æŽ¥ç€æ‰§è¡Œ 

;===============================================================================
SECTION data_1 align=16 vstart=0

    msg0 db '  This is NASM - the famous Netwide Assembler. '
         db 'Back at SourceForge and in intensive development! '
         db 'Get the current versions from http://www.nasm.us/.'
         db 0x0d,0x0a,0x0d,0x0a
         db '  Example code for calculate 1+2+...+1000:',0x0d,0x0a,0x0d,0x0a
         db '     xor dx,dx',0x0d,0x0a
         db '     xor ax,ax',0x0d,0x0a
         db '     xor cx,cx',0x0d,0x0a
         db '  @@:',0x0d,0x0a
         db '     inc cx',0x0d,0x0a
         db '     add ax,cx',0x0d,0x0a
         db '     adc dx,0',0x0d,0x0a
         db '     inc cx',0x0d,0x0a
         db '     cmp cx,1000',0x0d,0x0a
         db '     jle @@',0x0d,0x0a
         db '     ... ...(Some other codes)',0x0d,0x0a,0x0d,0x0a
         db 0

;===============================================================================
SECTION data_2 align=16 vstart=0

    msg1 db '  The above contents is written by LeeChung. '
         db '2011-05-06'
         db 0

;===============================================================================
SECTION stack align=16 vstart=0

         resb 256

stack_end:  

;===============================================================================
SECTION trail align=16

program_end:</pre></body></html>