端口读写分别用in和out,移位大于1时移位数先存在cl里。CMOS RAM在70h端口输入的是读写的地址,71h存储的地址存储的字节内容。
cpu能直接读取的只有寄存器,内存和端口。
访问CMOS RAM读取系统时间:
View Code
1 ;中断时的入栈顺序是pushf,push cs, push ip 2 assume cs : codesg, ss : stacksg 3 4 stacksg SEGMENT 5 dw 16 dup (0) 6 stacksg ENDS 7 8 9 10 codesg SEGMENT 11 12 start: mov al, 9 13 out 70h, al 14 in al, 71h 15 16 mov bx, 0b800h 17 mov ds, bx 18 19 mov si, 160 * 12 + 36 * 2 20 mov bl, al 21 mov cl, 4 22 and bl, 00001111b 23 shr al, cl 24 add bl, 30h 25 add al, 30h 26 27 mov ah, al 28 mov al, bl 29 mov bl, ah 30 31 mov [si], bl 32 mov byte ptr [si + 1], 02h 33 add si, 2 34 mov [si], al 35 mov byte ptr [si + 1], 02h 36 add si, 2 37 mov byte ptr [si], '/' 38 mov byte ptr [si + 1], 02h 39 add si, 2 40 41 mov al, 8 42 out 70h, al 43 in al, 71h 44 45 mov bl, al 46 mov cl, 4 47 and bl, 00001111b 48 shr al, cl 49 add bl, 30h 50 add al, 30h 51 52 mov ah, al 53 mov al, bl 54 mov bl, ah 55 56 mov [si], bl 57 mov byte ptr [si + 1], 02h 58 add si, 2 59 mov [si], al 60 mov byte ptr [si + 1], 02h 61 add si, 2 62 mov byte ptr [si], '/' 63 mov byte ptr [si + 1], 02h 64 add si, 2 65 66 mov al, 7 67 out 70h, al 68 in al, 71h 69 70 mov bl, al 71 mov cl, 4 72 and bl, 00001111b 73 shr al, cl 74 add bl, 30h 75 add al, 30h 76 77 mov ah, al 78 mov al, bl 79 mov bl, ah 80 81 mov [si], bl 82 mov byte ptr [si + 1], 02h 83 add si, 2 84 mov [si], al 85 mov byte ptr [si + 1], 02h 86 add si, 2 87 mov byte ptr [si], ' ' 88 mov byte ptr [si + 1], 02h 89 add si, 2 90 91 92 ;hour min second 93 mov al, 4 94 out 70h, al 95 in al, 71h 96 97 mov bl, al 98 mov cl, 4 99 and bl, 00001111b 100 shr al, cl 101 add bl, 30h 102 add al, 30h 103 104 mov ah, al 105 mov al, bl 106 mov bl, ah 107 108 mov [si], bl 109 mov byte ptr [si + 1], 02h 110 add si, 2 111 mov [si], al 112 mov byte ptr [si + 1], 02h 113 add si, 2 114 mov byte ptr [si], ':' 115 mov byte ptr [si + 1], 02h 116 add si, 2 117 118 mov al, 2 119 out 70h, al 120 in al, 71h 121 122 mov bl, al 123 mov cl, 4 124 and bl, 00001111b 125 shr al, cl 126 add bl, 30h 127 add al, 30h 128 129 mov ah, al 130 mov al, bl 131 mov bl, ah 132 133 mov [si], bl 134 mov byte ptr [si + 1], 02h 135 add si, 2 136 mov [si], al 137 mov byte ptr [si + 1], 02h 138 add si, 2 139 mov byte ptr [si], ':' 140 mov byte ptr [si + 1], 02h 141 add si, 2 142 143 mov al, 0 144 out 70h, al 145 in al, 71h 146 147 148 mov bl, al 149 mov cl, 4 150 and bl, 00001111b 151 shr al, cl 152 add bl, 30h 153 add al, 30h 154 155 mov ah, al 156 mov al, bl 157 mov bl, ah 158 159 mov [si], bl 160 mov byte ptr [si + 1], 02h 161 add si, 2 162 mov [si], al 163 mov byte ptr [si + 1], 02h 164 add si, 2 165 166 mov ax, 4c00h 167 int 21h 168 codesg ENDS 169 END start
显示如下,如果一直循环到start标号处,可以动态更新时间,效果不错。