寄存器简介
| 寄存器名称 | 功能 | 操作 |
|---|---|---|
| ax | 累加寄存器 | 经常使用,可以作为存储器看待 |
| bx | 基础寄存器 | 经常使用,访问内存时[]中只可以使用bx/bp/si/di和数字索引,默认使用的段寄存器为ds |
| cx | 循环寄存器 | 在使用loop做循环处理时,根据cx的值判断还有几次循环 |
| dx | 备用寄存器 | 在做除法时,对32位被除数存储时,高位放在dx中 |
| sp | 栈顶指针 | 在出栈、入栈时结合ss,对ss:sp处的内存进行操作 |
| bp | 指针寄存器 | 在未指明段寄存器的情况下,使用[bp]默认段寄存器为ss |
| si | 变址寄存器 | 在未指明段寄存器的情况下,使用[si]默认段寄存器为ds |
| di | 变址寄存器 | 在未指明段寄存器的情况下,使用[di]默认段寄存器为ds |
| ds | 段地址寄存器 | 通常指向初始化程序的内存代码段地址,在ds地址之后是psp程序前缀,大小为10H——16个字节,之后是程序运行的第一条指令地址,ds通常用于操作内存的段地址寄存器 |
| es | 段地址寄存器 | 可以用于存放段地址,可以作为备用段地址 |
| ss | 指针基址寄存器 | 可以用于存放指针段地址,通常与sp共同使用 |
| cs | 指令地址寄存器 | 可以用于存放下一个运行指令的地址,cs:ip |
| ip | 指令偏移寄存器 | cs:ip |
实验案例1
已有数据:
db '1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985','1986','1987'
db '1988','1989','1990','1991','1992','1993','1994','1995'
以上是21年的字符串
dd 16,22,382,1356,2390,8000,16000,2486,50065,97479,140417,197514,345980,590827,803530
dd 1183000,1843000,2759000,3753000,4649000,5937000
以上是21年公司的收入
dw 3,7,9,13,28,38,130,220,476,778,101,1442,2258,2793,4037,5635,8826,11542,14430,15257,17800
以上是21年公司雇佣的人数
table segment
db 21 dup('year summ ne ?? ')
table ends
通过编程将data中的数据写入到table中,并计算21年的人均收入(取整)
汇编实现:
assume cs:codesg
stack segment
db '1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985','1986','1987'
db '1988','1989','1990','1991','1992','1993','1994','1995'
dd 16,22,382,1356,2390,8000,16000,2486,50065,97479,140417,197514,345980,590827,803530
dd 1183000,1843000,2759000,3753000,4649000,5937000
dw 3,7,9,13,28,38,130,220,476,778,101,1442,2258,2793,4037,5635,8826,11542,14430,15257,17800
stack ends
table segment
db 21 dup('year summ ne ?? ')
table ends
codesg segment
start:
mov ax,stack
mov ss,ax
mov sp,0H
mov ax,table
mov ds,ax
mov cx,21
mov bx,0
s:
pop ax
mov ds:[bx],ax
pop ax
mov ds:[bx+2],ax
add bx,16
loop s
mov cx,21
mov bx,5
s0:
pop ax
mov ds:[bx],ax
pop ax
mov ds:[bx+2],ax
add bx,16
loop s0
mov cx,21
mov bx,10
s1:
pop ax
mov ds:[bx],ax
add bx,16
loop s1
mov cx,21
mov bx,0
s2:
mov ax,ds:[bx+5]
mov dx,ds:[bx+7]
div word ptr ds:[bx+10]
mov ds:[bx+13],ax
add bx,16
loop s2
mov ax,4c00h
int 21h
codesg ends
end start
实验案例2
在DOS窗口中显示字符,其中B8000H~BFFFFH共32KB的空间,这是一个缓冲区,向此缓冲区写入数据,写入的内容将立即出现在显示器上。其中奇数位地址为显示的字符内容,偶数位地址为显示的颜色(RGB,前景色,背景色)
代码实现:其中在向寄存器中写入B800H时,由于十六进制不可以以字母开头,所有在B800H前加上一个0
assume cs:code
data segment
db 'conversation'
data ends
code segment
start:
mov ax,0b800h
mov ds,ax
mov bx,0
mov byte ptr [bx],41h
mov byte ptr [bx].1h,02h
mov byte ptr [bx].2h,42h
mov byte ptr [bx].3h,02h
mov byte ptr [bx].4h,43h
mov byte ptr [bx].5h,02h
mov byte ptr [bx].6h,44h
mov byte ptr [bx].7h,02h
mov ax,4c00h
int 21h
code ends
end start