1. when accessing the port, the CPU uses the port address to locate the port. Because the chip where the port is located is connected to the CPU through the bus, the port address is transmitted through the address bus like the memory address.
2. In the PC system, the CPU can locate a maximum of 64 kB ports, and the port address range is 0 ~ 65535
3. Memory read/write commands such as mov, push, and pop cannot be used for reading and writing ports. There are only two read/write commands on the port: In and out, which are used to read and write data from the port and to the port respectively.
4. In the in and out commands, you can only use ax or Al to store the data read from the port or the data to be sent to the port.
5. Use al to access 8-bit ports and ax to access 16-bit ports.
6. 0 ~ When reading and writing ports less than 255:
In Al, 20 h; read a byte from Port 20 h
Out 20 h, Al; write a byte to Port 20 h
7. For 256 ~ When reading and writing the 65535 port, put the port number in DX:
MoV dx, 3f8h; send the port number 3f8h to DX
Int Al, DX; read one byte from Port 3f8h
Out dx, Al; write a byte to port 3f8h
SHL and SHR commands
1. SHL is the logic left shift command. Its function is:
1) shift data in a register or memory unit to the left;
2) write the last removed digit to CF;
3) use 0 to add the second digit.
2. SHR is a logical right shift command, which is the opposite of SHL.
1) shift data in a register or memory unit to the right;
2) write the last removed digit to CF;
3) use 0 to add the highest bit.
3. If the number of digits to be moved is greater than 1, the number of digits to be moved must be placed in cl. If you only move one digit, you can write it directly.
4. shifts the logic of X to the left, which is equivalent to executing x = x * 2 and shifting the logic of X to the right, which is equivalent to executing x = X/2.
Time information stored in CMOS RAM
1. in cmos ram, the current time is stored: year, month, day, hour, minute, and second. The length of the six pieces of information is 1 byte, and the storage unit is:
Seconds: 0: 2: 4: July: 8: 9
The data is stored as BCD codes. BCD code is a four-digit binary representation of the decimal code.
2. One byte can represent two BCD codes. The Unit in cmos ram that stores the time information stores two decimal numbers represented by two BCD codes. The BCD code with four digits in height represents ten digits, and the BCD code with four digits in height represents one digit.
3. If the BCD code value is a decimal digital value, the BCD code value + 30 h = the ASCII code corresponding to the decimal number.
A self-written assembler that displays the current time and date:
Assume Cs: codesg, SS: stacksg
Stacksg segment
DW 16 DUP (0)
Stacksg ends
Codesg segment
Start:
MoV Al, 9; Year
Out 70 h, Al
In Al, 71 h
MoV BX, 0b800h
MoV ds, BX; 25*80
MoV Si, 160*24 + 0*2; each character occupies 2 bytes, and N * 2 determines the column Coordinate
MoV BL, Al; column 0 in 25 rows
MoV cl, 4
And BL, 1271111b
SHR Al, Cl
Add BL, 30 h
Add Al, 30 h
MoV ah, Al
MoV Al, BL
MoV BL, ah
MoV [Si], BL
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV [Si], Al
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV byte PTR [Si], '/'
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV Al, 8; month
Out 70 h, Al
In Al, 71 h
MoV BL, Al
MoV cl, 4
And BL, 1271111b
SHR Al, Cl
Add BL, 30 h
Add Al, 30 h
MoV ah, Al
MoV Al, BL
MoV BL, ah
MoV [Si], BL
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV [Si], Al
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV byte PTR [Si], '/'
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV Al, 7; Day
Out 70 h, Al
In Al, 71 h
MoV BL, Al
MoV cl, 4
And BL, 1271111b
SHR Al, Cl
Add BL, 30 h
Add Al, 30 h
MoV ah, Al
MoV Al, BL
MoV BL, ah
MoV [Si], BL
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV [Si], Al
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV byte PTR [Si],''
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV Al, 4; hour
Out 70 h, Al
In Al, 71 h
MoV BL, Al
MoV cl, 4
And BL, 1271111b
SHR Al, Cl
Add BL, 30 h
Add Al, 30 h
MoV ah, Al
MoV Al, BL
MoV BL, ah
MoV [Si], BL
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV [Si], Al
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV byte PTR [Si], ':'
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV Al, 2; minute
Out 70 h, Al
In Al, 71 h
MoV BL, Al
MoV cl, 4
And BL, 1271111b
SHR Al, Cl
Add BL, 30 h
Add Al, 30 h
MoV ah, Al
MoV Al, BL
MoV BL, ah
MoV [Si], BL
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV [Si], Al
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV byte PTR [Si], ':'
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV Al, 0; second
Out 70 h, Al
In Al, 71 h
MoV BL, Al
MoV cl, 4
And BL, 1271111b
SHR Al, Cl
Add BL, 30 h
Add Al, 30 h
MoV ah, Al
MoV Al, BL
MoV BL, ah
MoV [Si], BL
MoV byte PTR [Si + 1], 0cah
Add Si, 2
MoV [Si], Al
MoV byte PTR [Si + 1], 0cah
Add Si, 2
JMP near PTR start; non-stop refresh time
MoV ax, 4c00h
Int 21 h
Codesg ends
End start