application of seven-way approach in structured data access (172th page of the book)
Experimental content
650) this.width=650; "Src=" http://home.51cto.com/thumb.php?w=600&h=600&t=f&url=http://s3.51cto.com/ Wyfs02/m02/59/fd/wkiol1tyjtbw2tcxaacmovmeydo504.jpg "width=" 426 "height=" 249 "alt=" Wkiol1tyjtbw2tcxaacmovmeydo504.jpg "/>
The data is already defined in the following program:
assume Cs:code SG
Data segment
DB'1975','1976','1977','1978','1980','1980','1981','1982','1983'
DB'1984','1985','1986','1987','1988','1989','1990','1991','1992'
DB ' 1993 ' , ' 1994 ' , ' 1995 '
The above is a string that represents seven years (4 bytes per string)
DD 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
DD 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000
Above is a DWORD Data ( 4 bytes each) representing the company's total revenue for the year
DW 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
DW 11542,14430,15257,17800
The above is the word data (2 bytes each) that represents the number of employees in the company for a year .
Data ends
Table Segment
db DUP (' year summ ne?? ' )
Table Ends
Code SG segment
Start
Code SG ends
End Start
programming: data annual per capita income ( rounding )
650) this.width=650; "Src=" http://home.51cto.com/thumb.php?w=600&h=600&t=f&url=http://s3.51cto.com/ Wyfs02/m01/5a/00/wkiom1tyjcptl6zzaaff3znoo7a642.jpg "width=" 568 "height=" 366 "alt=" Wkiom1tyjcptl6zzaaff3znoo7a642.jpg "/>
Here is the complete code for my answer:
:>----------------------------------------------------------------------------------------
Assume CS:CODESG
Data segment
DB ' 1975 ', ' 1976 ', ' 1977 ', ' 1978 ', ' 1979 ', ' 1980 ', ' 1981 ', ' 1982 ', ' 1983 '
DB ' 1984 ', ' 1985 ', ' 1986 ', ' 1987 ', ' 1988 ', ' 1989 ', ' 1990 ', ' 1991 ', ' 1992 '
DB ' 1993 ', ' 1994 ', ' 1995 '
DD 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
DD 345980,590827,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
Data ends
Stack segment
DW 0,0,0,0,0,0,0,0; To better understand the stack, the stack is used to hold the data
Stack ends
Table Segment
DB DUP (' Year Summ ne?? ‘)
Table Ends
CODESG segment
Start:mov ax, data; Initialize DS segment Register to data
MOV ds, ax
mov ax, table; Initialize the ES segment register to table
MOV es, ax
mov ax, stack; initialize SS segment register to Stack
mov ss, ax
mov sp, 10H; initialize SS-Stack-segment pointer sp
MOV bx, 0; Use BX to control the row movement of table data, move 16 bytes at a time
mov bp, 0; Use BP to point to the first address of the Data section data (Additional function: staging the stack data)
mov si, 0; Use SI to move the data segment with BP
mov di, 0; Use di to move the first address of each column of data with BX to access each row of the table
Push Si first into the stack because SI is used to move the data in and out, but the date data and the total revenue
The amount of data moved is 4 bytes, and the number of employees is 2 bytes, in order to use
Si to unify the operation, so think of using the stack to save Si to take the average income of the movement.
mov cx, 15H; CX controls row Movement to table (total 21 rows =15h)
S0:mov ax, [si]
MOV dx, [si].2h
MOV ES:[BX], ax
mov es:[bx].2h, DX
The above is the date data that is re-created into data into the ' year ' of each row in the table
MOV bp, 54H
mov di, 5H
mov ax, Ds:[bp][si]
MOV dx, ds:[bp][si].2h
MOV Es:[bx][di], ax
mov es:[bx][di].2h, DX
The above is the ' Summ ' of the date data in the database to each row in the table
Pop bp
Push SI
mov si, bp
; Take out the moving amount of the average income of SI 2, and save the SI with a moving volume of 4
MOV bp, 0a8h
mov di, 0DH
div word ptr ds:[bp][si]
MOV Es:[bx][di], ax
Calculate the average income and save it to the '?? ' in each row of the table.
mov di, 0AH
mov ax, Ds:[bp][si]
MOV Es:[bx][di], ax
Copy the number of company employees from data and save to ' ne ' in each row of the table
Add Si, 2H; the current Si-per-2 movement (as the number of SI operable data)
Pop bp
Push SI
mov si, bp
The above is to change SI to 4 each time the movement (that is, si to the operating date, income data), and will
Si each add 2 of the moving amount into the stack to save
Add Si, 4H; the current Si movement of 4 (SI operable date, data portion of income data)
Add bx, 10H; jumps to the first address of the next line of table
loop S0; Repeat the above operation
mov ax, 4c00h
int 21H
CODESG ends
End Start
:<-----------------------------------------------------------------------------------------
The following is the data in the post-run table segment and the corresponding ASCII code representation:
650) this.width=650; "Src=" http://home.51cto.com/thumb.php?w=600&h=600&t=f&url=http://s3.51cto.com/ Wyfs02/m01/59/fd/wkiol1tymwld6ehbaaqk0hzxzng526.jpg "width=" "height=" 311 "alt=" Wkiol1tymwld6ehbaaqk0hzxzng526.jpg "/>
Summarize:
Code is a bit long, because it is still just a short time, but the whole experiment to do down the table in memory of the preservation has a very clear understanding, continue to refuel learning! If everyone has a better code welcome to share.
-------------The above exercises section and code reference Yu Wang Teacher's << assembly language >> Second Edition----------------
This article is from the "9256624" blog, please be sure to keep this source http://9266624.blog.51cto.com/9256624/1616257
Learning << Assembly language-Wang Shuang >> This book a period of time, self-completed a real question