實驗7主要是尋址方式與div指令的綜合運用,這也是他的難點所在。
注:代碼經masm5編譯通過
div是個除法指令
先設a,b,c,d為整數,b≠0且0≤d<|b|
則 a=bc+d
其中a為被除數在div指令中有16位與32位之分。16位預設放在AX中,32位分高16位與低16位,高16位預設放dx低16位預設放ax。
便于記憶可以做如下了解:
若a在16位的值為1111111111111111b,則在32位中的值為0000000000000000111111111111111b。是以在32位中低16位預設放ax。
b為除數在div指令中有8位與16位之分,放在寄存器或記憶體單元中。8位的b對應16位的a,16位的b對應32位的a。
c為商d為餘數,如果b為8位,則c放al,d放ah。若幹b為16位,c放ax,d放dx。
以上便于記憶可以做如下了解:
a(16位,放AX)=b(8位,放8位寄存器或記憶體單元)c(放al,暫時不考慮溢出)+d(放ah,暫時不考慮溢出)
a(32位,高位dx 低位ax)=b(16位,放16位寄存器或記憶體單元)c(放ax,暫時不考慮溢出)+d(放dx,暫時不考慮溢出)
看表格:
1975 | 1976 | 1977 | 1978 | 1979 | 1980 | 1981 | 1982 | 1983 | 1984 | 1985 | 1986 | 1987 | 1988 | 1989 | 1990 | 1991 | 1992 | 1993 | 1994 | 1995 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
16 | 22 | 382 | 1356 | 2390 | 8000 | 16000 | 24486 | 50065 | 97479 | 140417 | 197514 | 345980 | 590827 | 803530 | 1183000 | 1843000 | 2759000 | 3753000 | 4649000 | 5937000 |
3 | 7 | 9 | 13 | 28 | 38 | 130 | 220 | 476 | 778 | 1001 | 1442 | 2258 | 2793 | 4037 | 5635 | 8226 | 11542 | 14430 | 15257 | 17800 |
表格1中1、2行的每一列資料占4個位元組,第三行資料每列占2個位元組。
第一行偏移位址範圍是0H~53H
第二行偏移位址範圍是54H~a7H
第三行偏移位址範圍是a7H~d0H
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
1 | 9 | 7 | 5 | 00 | 00 | 00 | 16H | 00 | 3H | ? | ? | |||
1 | 9 | 7 | 6 | 00 | 00 | 00 | 22H | 00 | 7H | ? | ? | |||
┆ | ┆ | ┆ | ┆ | ┆ | ┆ | ┆ | ┆ | ┆ | ┆ | ┆ | ┆ | |||
1 | 9 | 9 | 4 | 00 | 46H | F0H | 28H | 3BH | 99H | ? | ? | |||
1 | 9 | 9 | 5 | 00 | 5AH | 97H | 68H | 45H | 88H | ? | ? |
表格2中第一行為偏移位址,二、三行每一列占1位元組
實驗7是要把表1中的三行資料按照順序依次move到表2中并進行div運算。是以可以先把表1中的資料按行來move到表2相應的單元中在進行div運算或者先把表1中的資料按列來move到表2相應的單元中在進行div運算。是以有兩種方式實作實驗7。
第一種按行:
1、用di定位表1第一行中的單元格,再用bx定位單元格中的具體資料data。
2、用si定位表2行的首位址,再用bx定位data相應的單元
3、因為有21條資料是以把1、2進行21次循環
代碼:
mov cx,21
s1:push cx
mov bx,0
mov cx,4
s0:mov al,ds:[di][bx]
mov es:[si][bx],al
inc bx
loop s0
add di,4
add si,16
pop cx
loop s1
4、用di定位表1第二行中的單元格,再用bx定位單元格中的具體資料data。
5、用si定位表2行的第五列,再用bx定位data相應的單元
6、因為有21條資料是以把1、2進行21次循環
代碼:
mov di,54h
mov si,5
mov cx,21
s1:push cx
mov bx,0
mov cx,4
s0:mov al,ds:[di][bx]
mov es:[si][bx],al
inc bx
loop s0
add di,4
add si,16
pop cx
loop s1
7、用di定位表1第3行中的單元格,再用bx定位單元格中的具體資料data。
8、用si定位表2行的A列,再用bx定位data相應的單元
9、因為有21條資料是以把1、2進行21次循環
mov di,0a7h
mov si,10
mov ax,21
s1:push ax
mov bx,0
mov cx,2
s0:mov al,ds:[di][bx]
mov es:[si][bx],al
inc bx
loop s0
add di,2
add si,16
pop cx
loop s1
10、用si定位表2第5列資料move到dx,在定位第7列資料move到ax
11、把表二第10列資料作為除數,商放表二第13列
12、此過程循環21次
代碼:
mov cx,21
s0:mov dx,es:[si].5
mov cx,es:[si].7
div word ptr es:[si].10
mov es:[si].13,ax
add si,16
loop s0
實驗7完整代碼如下:
注:代碼經masm5編譯通過
第一種按行代碼如下:
assume cs:codesg,ds:datasg,es:tablesg,ss:stacksg
datasg segment
db '1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985'
db '1986','1987','1988','1989','1990','1991','1992','1993','1994','1995'
dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514,345980,590827
dd 803530,1183000,1843000,2759000,3753000,4649000,5937000
dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
dw 11542,14430,15257,17800
datasg ends
tablesg segment
db 21 dup ('year summ ne ?? ')
tablesg ends
stacksg segment
dd 0,0,0,0
stacksg ends
codesg segment
;首先初始化寄存器
start:mov ax,datasg
mov ds,ax
mov ax,tablesg
mov es,ax
mov ax,stacksg
mov ss,ax
mov sp,0010H
mov di,0000H
mov si,0000H
mov bx,0000H
;處理表1的1、2行
mov cx,0002H
s2: push cx
mov cx,0015H
s0: push cx
mov bx,0000H
mov cx,0004h
s1: mov al,ds:[di][bx]
mov es:[si][bx],al
inc bx
loop s1
add di,0004H
add si,0010H
pop cx
loop s0
mov si,0005H
pop cx
loop s2
;處理表1的第三行
mov si,000Ah
mov bx,0000h
mov cx,0015H
s4: push cx
mov cx,0002H
s3: mov al,ds:[di][bx]
mov es:[si][bx],al
inc bx
loop s3
add di,0002H
add si,0010H
mov bx,0
pop cx
loop s4
;處理表2除法
mov si,0
mov cx,0015H
s5: mov ax,es:[si].5
mov dx,es:[si].7
div word ptr es:[si].0AH
mov es:[si].0DH,ax
add si,0010H
loop s5
mov ax,4c00h
int 21h
codesg ends
end start
第二種按列代碼如下:
assume cs:codesg,ds:datasg,es:tablesg,ss:stacksg
datasg segment
db '1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985'
db '1986','1987','1988','1989','1990','1991','1992','1993','1994','1995'
dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514,345980,590827
dd 803530,1183000,1843000,2759000,3753000,4649000,5937000
dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
dw 11542,14430,15257,17800
datasg ends
tablesg segment
db 21 dup ('year summ ne ?? ')
tablesg ends
stacksg segment
dd 0,0,0,0
stacksg ends
codesg segment
start: mov ax,datasg
mov ds,ax
mov ax,tablesg
mov es,ax
mov ax,stacksg
mov ss,ax
mov sp,0010H
mov si,0000H
mov di,0000H
mov bx,0000H
mov cx,0015H
s0: push cx
push bx
mov bx,0000H
mov cx,0004H
s1: mov al,00H[di]
mov es:[si][bx],al
mov al,54H[di]
mov es:[si].05H[bx],al
inc bx
inc di
loop s1
pop bx
mov ax,0A8H[bx]
mov es:[si].0AH,ax
add bx,0002H
add si,0010H
pop cx
loop s0
mov si,0000H
mov cx,0015H
s2: mov ax,es:[si].05H
mov dx,es:[si].07H
div word ptr es:[si].0AH
mov es:[si].0dh,ax
add si,0010H
loop s2
mov ax,4c00h
int 21h
codesg ends
end start