天天看點

彙編語言王爽 實驗10.1

初學彙編 做的不好 但是能用:

assume cs:code

data segment

db 'welcome to masm! ',0

data ends

code segment

start: mov dh,8;line

       mov dl,3;column

       mov cl,2;color

       mov ax,data

       mov ds,ax

       mov si,0

       call show_str

       mov ax,4c00h

       int 21h

show_str: push cx ;   show_str(dh:line,dl:colum,cx:color,ds:[0]-ds:['0'])

          push si

          push bx

          push ax

          push dx

          mov ax,0b800h

          mov es,ax   ;display seg mem

          mov al,160

          dec dh

          mul dh; ATTENTION:ax==the offest address of character

          mov bx,ax;ax is used to another multiple

          mov al,2

          mul dl

          sub ax,2

          add bx,ax

          mov si,bx

          mov bx,cx;cx is used for both loop and color, therefore use unsed bx to store color

    ;step 1:

         ; first fill color information in mem 

         push si

    s1:  mov ch,0

         mov cl,ds:[di]; sourse data

         jcxz ok0

         mov es:[si+1],bx

         add si,2

         inc di

    loop s1

    ok0: 

         mov di,0

         pop si

    ;step 2: 

    ;fill other spaces with ASCII code

    s2:   mov cl,ds:[di]

          jcxz ok1

          mov bl,ds:[di];

          mov es:[si],bl;

          add si,2

彙編語言王爽 實驗10.1

          inc di

          loop s2

    ok1:  pop dx

          pop ax

          pop bx

          pop si

          pop cx

    ret        

code ends

end start

繼續閱讀