2015-04-05 130 views
2
cseg segment 
assume cs:cseg, ds:cseg 
org 100H 
begin: 
       mov es,cs:[video] 
       mov ax,3 
       int 10h 
       mov cs:[col],0fh 
       mov di,10    ;greeting msg will be printed after 10 spaces 
       lea si,greeting 
       call mess 
       call nline   
       call jan 
       call nline 
       mov ah,4ch 
       int 21h 

col    db 0 
greeting  db "Welcome to the 2015 Calendar ",0 
video   dw 0b800h 
january   db "   January$",  
string   db "Sun Mon Tue Wed Thu Fri Sat$" 
string1   db "   1 2 3 4 5$" 
string2   db " 6 7 8 9 10 11 12$" 
string3   db "13 14 15 16 17 18 19$" 
string4   db "20 21 22 23 24 25 26$" 
string5   db "27 28 29 30 31$" 

mess   proc 
       push ax 
       mov ah,cs:[col] 
       mov bh, 30 
conmess: 
       mov al,cs:[si] 
       or al,al 
       jz endmess 
       mov es:[di],ax 
       mov es:[di+1],bh 
       inc si 
       add di,2 
       jmp conmess 
endmess: 
       pop ax 
       ret 
mess   endp 

nline   proc 
       mov ah, 2     ; carriage return 
       mov DL, 0DH 
       int 21H  
       mov DL, 0AH     ; line feed 
       int 21H 
       ret 
nline   endp 

print: 
       ;printing the line 
       mov bh,10h ;color attribute 
       mov ah,9 
       mov al,0 ;avoding extra characters 
       int 10h ;printing color 
       int 21h 
       ret 

jan    proc 
       lea dx,january    ; load & display the STRIN 
       call print 
       call nline 
       lea dx, string    ; load & display the STRING 
       call print 
       call nline 
       lea dx, string1    ; load & display the STRING 
       call print 
       call nline 
       lea DX, string2    ; load & display the STRING 
       call print 
       call nline 
       lea DX, string3    ; load & display the STRING 
       call print 
       call nline 
       lea DX, string4    ; load & display the STRING 
       call print  
       call nline 
       lea DX, string5    ; load & display the STRING 
       call print 
       call nline 
       ret 
jan    endp 

cseg ends 
end begin 

回答

2
assume cs:cseg, ds:cseg 
org 100H 

打印整個日曆因爲你使用org 100h我假設你正在寫在DOS'.COM格式的可執行文件。

mov di,10    ;greeting msg will be printed after 10 spaces 

要產生10個空格,需要設置DI = 20,因爲在0B800h的視頻RAM中每個字符佔用2個字節。

mess proc 
    push ax 
    mov ah,cs:[col] 
    mov bh, 30   ; You don't need this line 
conmess: 
    mov al,cs:[si] 
    or al,al 
    jz endmess 
    mov es:[di],ax 
    mov es:[di+1],bh ; You don't need this line 
    inc si 
    add di,2 
    jmp conmess 
endmess: 
    pop ax 
    ret 
mess endp 

通過直接寫入視頻RAM顯示問候消息。爲什麼要插入2種方法來定義屬性字節?

print: 
mov bh,10h ; Delete this line 
mov ah,9 
mov al,0 ; Delete this line 
int 10h  ; Delete this line 
int 21h 
ret 

其餘的寫作是通過DOS函數完成的。這打印例程似乎混合BIOS和DOS功能!對於DOS,您只需要AH = 9

mov ah,4ch 
int 21h 

Terminate函數期望您在AL寄存器中定義退出代碼。使用mov ax,4C00h

代替nline生成CRLF的繁瑣調用,您可以輕鬆地將這兩個字節寫入要輸出的字符串中。
像這個例子

string2   db " 6 7 8 9 10 11 12",13,10,"$" 

你的大多數程序都使用PROC/ENDP但打印聲明是沒有的。請選擇一個系統並堅持下去。

編輯

由於您的所有字符串都在單獨的行顯示的最簡單的方法,給他們顏色是使用所需的屬性擦拭當前行。以下是你如何做第一個字符串

mov ax,0920h     \ 
mov bx,001Eh ;Yellow on Blue | Best put this in a subroutine! 
mov cx,80      | 
int 10h      /
lea dx,january 
call print 
call nline 
+0

非常感謝。但是,還有一件事我需要打印它的顏色。我遇到了麻煩。無論如何要用彩色高亮格式寫所有這些字符串? – 0ptimus 2015-04-05 16:01:48

+0

我給輸出添加了顏色。 – 2015-04-05 18:12:18

+0

謝謝此代碼完全工作 – 0ptimus 2015-04-05 23:29:28