Assembly Language Learning Chapter 14th-Port

Source: Internet
Author: User

this blog series reference from << assembly Language >> third edition, author: Wang Shuang


all kinds of memory are connected with CPU via address bus, data bus and control bus. The CPU is a unified address for the storage unit composed of these various memory. In addition to the various memory and CPU connections, there are several chips and CPUs connected:(1) various interface cards (such as network cards, video cards) on the chip, they control the interface card work (2) the interface chip on the motherboard, the CPU accesses some peripherals through them(3) Other chips for storing relevant system information or for related input and output processing
in these chips, there are registers that can be read and written by the CPU, although the registers are physically different chips, but there are two identical points: (1) are connected to the bus of the CPU, of course, the connection is through the chip on which they reside (2) when the CPU reads or writes to them, it sends the port read-write command to their chip via the control line.
from the CPU's point of view, the CPU addresses these ports uniformly, and each port has a unique address in the address space. The CPU can directly read and write data directly from three places: memory address space, port, CPU internal register.
14.1-Port Read/write
the CPU and the chip on which the port resides are connected via address bus, so the port address and memory address are transmitted via address bus. In a PC system, the CPU can locate up to 64KB different ports. The address range for the port is 0~65535.The read/write to the port can only be used in and out instructions. differences in access memory and access ports:(1) Access to memory:mov ax,ds:[8]; Assume pre-Execution (DS) =8To perform the steps:one. The CPU sends address information 8 through the address linetwo. The CPU sends out a memory read command through the control line, selects the memory chip, notifies it, and will read the data from itthree. Memory feeds the data in unit 8th into the CPU via the data cable(2) Access port:in al,60h; reads a byte from port 60thTo perform the steps:one. The CPU sends address information 60h through the address linetwo. The CPU sends a port command through the control line to tell the chip to read the port's informationthree. The chip of the port sends the information of the 60h port to Al
14.2 CMOS RAM Chip
There is a CMOS RAM chip in the PC, the chip features the following:1. Ram memory containing a clock and a 128 storage unit2. The chip is powered by a battery. So it's still working after the shutdown .3.128 bytes of RAM, where 0~0DH is used to save time information, and most of the rest is used to save the system configuration for BIOS reading at system startup, biosIt also provides programs that enable us to configure the information in CMOS RAM at boot time4. The chip has two ports 70h and 71h, using these two ports to achieve the reading and writing of CMOS RAM. The 5.70h is the address port, which holds the address unit of the CMOS to be read. 71H is the data port that holds the data to write or write. For example, the 2nd unit reading CMOS is divided into the following two steps:2 fed into 70hread the contents of unit 2nd from 71h

14.3 SHL and SHR directives
SHL and SHR for logical shift operationsSHL is a logical left shift operation with the function of:(1) Move data from one register or memory unit to the left(2) One of the last moved out is written to CF(3) minimum position with 0 supplementFor example:
MOV AL,01001000BSHL al,1
After execution (AL) =10010000b,cf=0if the number of moving bits is greater than 1, the number of moving digits must be saved in Cl, for example:
mov Al,01010001bmov CL,3SHL al,cl
You can see that moving the X logic to the left is equivalent to x=x*2
The SHR is a logical right shift operation with the following functions:(1) Move data from one register or memory unit to the right(2) One of the last moved out is written to CF(3) minimum bit 0SupplementFor example:
MOV al,10000001bshr al,1
After execution (AL) =01000000b,cf=1
The same,if the number of moving digits is greater than 1, the number of moving digits must be saved in CL
you can see that moving the X logic to the left is equivalent to X=X/2

14.4 The time information stored in CMOS RAM
in CMOS, the current time is stored: year, month, day, hour, minute, second. The 6 messages are all 1 bytes long and the storage unit is:seconds: 0 Points: 2 o'clock: 4th: July: 8 Year: 9This data is stored in BCD mode. The BCD code is as follows:
For example, the value 26, the BCD code is expressed as: 0010 0110visible in CMOS, a byte represents a two-bit BCD code, a high four-bit BCD represents 10 bits, and a low four-bit BCD represents a single digit
problem, display the current month in the middle of the screen:a BCD code for the current month is read from the 8th Address unit of CMOS RAM
mov al,8out 70h,alin al.71h
The second will display the month in the BCD code to the screen in decimal formBCD value = Decimal code value, the BCD code value +30h= the ASCII code corresponding to the decimal numberA byte is read from the CMOS RAM unit 8th, and the BCD code that is divided into two is worth the data.
mov Ah,almov cl,4shr al,cland al,00001111b
Display (AH) +30h and (AL) +30h corresponding ASCII characters, the complete program is as follows:
Assume Cs:codecode Segmentstart:mov al,8 out       70h,al       in  al,71h       mov ah,al       mov cl,4       shr ah,cl and       al,00001111b       add ah,30h       add al,30h       mov bx,0b800h       mov es,bx       mov byte ptr es:[160*12+40*2 ],ah       mov byte ptr es:[160*12+40*2+2],al       mov ax,4c00h       int 21hcode endsend start





Assembly Language Learning Chapter 14th-Port

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.