Lection 5. Arrays презентация

Содержание


Lection 5. Arrays 
 
 an array is the structured typeArrays 
 In order to understand possibilities features of treatment ofDescription and initialization of array in the program 
 Special facilitiesDescription and initialization of array in the program 
 1.	By enumerationDescription and initialization of array in the program
 1.	By enumeration ofDescription and initialization of array in the program
 Dignity of directiveDescription and initialization of array in the program
 As a resultDescription and initialization of array in the program
 1.	By enumeration ofMODEL small
 MODEL small
 STACK 256
 .data
 mes	db	0ah,0dh,'Масив- ','$'
 mas	db	10 dupAccess to the array cells 
 During work it is necessaryAccess to the array cells
 So, the same storage area canAccess to the array cells 
 The same considering can beAccess to the array cells 
 In an assembly language theAccess to the array cells
  Lets once again we willAccess to the array cells
  Let this sequence of numbersAccess to the array cells
 In general case for the receiptAccess to the array cells
 Architecture of microprocessor gives comfortable enoughAccess to the array cells
 For example : 
 	
 
Access to the array cells
 The base-displacement indexed addressing with displacementAccess to the array cells
 A microprocessor allows to scale anMODEL	small
 MODEL	small
 STACK	256
 .data	
 ;text
 mes1	db ‘not equal 0!$',0ah,0dh
 mes2	db 'dec	cx		
 	dec	cx		
 	jcxz	exit	
 ;cx=0? Yes — go to exit
 	jmp	compare	
 ;noA few words about the agreements
 If for description of addressA few words about the agreements
 If for the task ofA few words about the agreements
 If for description of addressA few words about the agreements
 We will notice that theMODEL	small
 MODEL	small
 STACK	256	
 .data
 N=5			
 ;number elements of array
 mas	db	5 dup



Слайды и текст этой презентации
Слайд 1
Описание слайда:
Lection 5. Arrays an array is the structured type of information, consisting of some number of elements of one type.


Слайд 2
Описание слайда:
Arrays In order to understand possibilities features of treatment of arrays in the programs on an assembler, it is needed to answer on the following questions: How to describe an array in the program? How to initialize an array, that how to set the initial values of his elements? How to organize access to the array cells? How to organize arrays with a dimension more by one? How to organize implementation of model operations with arrays?

Слайд 3
Описание слайда:
Description and initialization of array in the program Special facilities of description of arrays in the programs of assembler, certainly, no. If it is necessary to use an array in the program of him it is needed to design by one of the following methods: 1. By enumeration of array cells in the field of operands of one of directives of data definition. At enumeration elements are divided by commas. For example: ;array of 5 elements. Size of each elements are 4 Bytes: mas dd 1,2,3,4,5

Слайд 4
Описание слайда:
Description and initialization of array in the program 1. By enumeration of array cells in the field of operands of one of directives of data definition. At enumeration elements are divided by commas. 2. Using the operator of reiteration of dup. For example: ;array of 5 zero elements. Size of each elements are 2 Bytes: mas dw 5 dup (0) Such method of determination is used for reservation of memory with a purpose placing and initializations of array cells.

Слайд 5
Описание слайда:
Description and initialization of array in the program 1. By enumeration of array cells in the field of operands of one of directives of data definition. At enumeration elements are divided by commas. 2. Using the operator of reiteration of dup. 3. Using the directives of label and rept. The pair of these directives can facilitate description of large arrays in memory and promote evident of such description. The directive of rept behaves to macro means of assembly language and the indicated number causes the reiteration one time the lines concluded between a directive and line of endm. For example, we will define an array byte in area of the memory marked by the identifier mas_b. In this case the directive of label determines the symbolic name of mas_b, like to that how it is done by the directives of reservation and initialization of memory.

Слайд 6
Описание слайда:
Description and initialization of array in the program Dignity of directive of label that she does not reserve memory, and only determines descriptions of object. In this case an object is a memory cell. Using a few directives of label, written down one by one, it is possible to appropriate different names and different type to the same storage area, that it is done in the following fragment: ... n=0 ... mas_b label byte mas_w label word rept 4 dw 0f1f0h endm

Слайд 7
Описание слайда:
Description and initialization of array in the program As a result a sequence from four words f1f0 will be created in memory. This sequence it is possible to interpret as array a byte or words depending on that, what name of region we will use in the program - mas_b or mas_w.

Слайд 8
Описание слайда:
Description and initialization of array in the program 1. By enumeration of array cells in the field of operands of one of directives of data definition. At enumeration elements are divided by commas. 2. Using the operator of reiteration of dup. 3. Using the directives of label and rept. 4. Use of cycle for initialization by the values of storage which it is possible afterwards to interpret as array area. We will look on the example of listing, how it is done.

Слайд 9
Описание слайда:
MODEL small MODEL small STACK 256 .data mes db 0ah,0dh,'Масив- ','$' mas db 10 dup (?) i db 0 .code main: mov ax,@data mov ds,ax xor ax,ax mov cx,10 mov si,0 go: mov bh,i mov mas[si],bh inc i inc si

Слайд 10
Описание слайда:
Access to the array cells During work it is necessary expressly to imagine with arrays, that all array cells are disposed in memory of computer consistently. On itself such location speaks nothing about setting and order of the use of these elements. And only only a programmer determines by the algorithm of treatment made to them, how it is needed to interpret this sequence byte, making an array.

Слайд 11
Описание слайда:
Access to the array cells So, the same storage area can be interpreted as 1 dimension array, and simultaneously the same information can be interpreted as 2 dimension array. All depends only on the algorithm of the these data processing in the concrete program. On itself information carry no information about the "semantic", or logical, type. Remember about this of principle moment.

Слайд 12
Описание слайда:
Access to the array cells The same considering can be spread on the indexes of array cells. An assembler is unaware of their existence and to him absolutely however, their numeral semantic values are which. In order to localize a certain array cell, to his name it is needed to add an index. Because we design an array, must look after about the design of index.

Слайд 13
Описание слайда:
Access to the array cells In an assembly language the indexes of arrays are ordinary addresses, but with them work as the special appearance. In other words, when at programing on an assembler we speak about an index, rather imply here under no number of element in an array, and some address.

Слайд 14
Описание слайда:
Access to the array cells Lets once again we will appeal to array declaration. For example, the sequence of information is statically certain in the program: mas dw 0,1,2,3,4,5

Слайд 15
Описание слайда:
Access to the array cells Let this sequence of numbers be interpreted as 1x array. It is determined size of every element by the directive of dw, that she is equal 2 bytes. To get access to the third element, it is needed to the address of array to add 6. Numeration of array cells in an assembler begins from a zero. That in our case the question, actually, is about a 4th array cell - 3, but a programmer knows only about it; to the microprocessor in this case however - he needs an address only.

Слайд 16
Описание слайда:
Access to the array cells In general case for the receipt of address of element in an array it is necessary to lay down the leading (base) address of array with work of index (number of element minus unit) of this element on the size of array cell: base + (index*size of element)

Слайд 17
Описание слайда:
Access to the array cells Architecture of microprocessor gives comfortable enough program-hardware facilities for work with arrays. Base and index registers allowing to realize a few modes of addressing of information behave to them. Using these modes of addressing, it is possible to organize effective work with arrays in memory. We will remember these modes: the indexed addressing with displacement is the mode of addressing, at which an effective address is formed from two components: permanent (base) - pointing of direct addresses of array as the name of identifier designating beginning of array; variable (index) - pointing of the name of index register.

Слайд 18
Описание слайда:
Access to the array cells For example : mas dw 0,1,2,3,4,5 ... mov si,4 ;move 3-th element of array mas into register ax: mov ax,mas[si]

Слайд 19
Описание слайда:
Access to the array cells The base-displacement indexed addressing with displacement is the mode of addressing, at which an effective address is formed maximum from three components: permanent (optional component), which the direct address of array as the name of identifier designating beginning of array can come forward as, or direct value; variable (base) - pointing of the name of base register; variable (index) - pointing of the name of index register. It is comfortably to use this type of addressing for treatment of 2x arrays.

Слайд 20
Описание слайда:
Access to the array cells A microprocessor allows to scale an index. It means that if to specify after the name of index register the sign of increase of "*" with a subsequent number 2, 4 or 8, content of index register will be increased on 2, 4 or 8, that be scaled. Application of scaling facilitates work with arrays, which have the size of elements, equal 2, 4 or 8 bytes, because a microprocessor produces correction of index for the receipt of address of a next array cell. We need only to load the value of the required index in an index register (considering from 0).

Слайд 21
Описание слайда:
MODEL small MODEL small STACK 256 .data ;text mes1 db ‘not equal 0!$',0ah,0dh mes2 db ' equal 0!$',0ah,0dh mes3 db 0ah,0dh,‘Element $' mas dw 2,7,0,0,1,9,3,6,0,8 ;array .code .486 main: mov ax,@data mov ds,ax ; ds connect with .Data xor ax,ax ;ax=0 prepare: mov cx,10 ; cx=10 mov esi,0 ;index into esi

Слайд 22
Описание слайда:
dec cx dec cx jcxz exit ;cx=0? Yes — go to exit jmp compare ;no — repeat loop equal: ;is equal 0 mov ah,09h ;output mes3 lea dx,mes3 int 21h mov ah,02h mov dx,si add dl,30h int 21h mov ah,09h ; output mes2

Слайд 23
Описание слайда:
A few words about the agreements If for description of address one register is used only, the question is about the base-displacement addressing and this register is examined as base: ;move byte from the ;adress in the register ebx: mov al,[ebx]

Слайд 24
Описание слайда:
A few words about the agreements If for the task of address the direct addressing (as an identifier) in combination with one register is used in a command, the question is about the indexed addressing. A register is considered index, and it is possible to use scaling for the receipt of address of necessary array cell: add eax,mas[ebx*4] ; eax + double word from ;adress mas + (ebx)*4

Слайд 25
Описание слайда:
A few words about the agreements If for description of address two registers are used, the question is about the basely-indexed addressing. A left register is examined as base, and right - as index. In general case on no principle it, but if we use scaling with one of registers, he always is index. But it is better to adhere to the certain agreements. Remember that application of registers of ebp/bp and esp/sp implies by default, that the segment constituent of address is in the register of ss.

Слайд 26
Описание слайда:
A few words about the agreements We will notice that the basely-indexed addressing is not forbidden to combine with the direct addressing or pointing of direct value. An address then will be formed as sum of all components. For example: mov ax,mas[ebx][ecx*2] ;adress of operand is equal [mas+(ebx)+(ecx)*2] ... sub dx,[ebx+8][ecx*4] ; adress of operand is equal [(ebx)+8+(ecx)*4] But mean that scaling is effective only then, when the dimension of array cells is equal a 2, 4 or 8 byte. If the dimension of elements is other, organizing the address to the array cells is needed in general a way, as described before.

Слайд 27
Описание слайда:
MODEL small MODEL small STACK 256 .data N=5 ;number elements of array mas db 5 dup (3 dup (0)) .code main: mov ax,@data mov ds,ax xor ax,ax ;обнулення ax mov si,0 ;0 у si mov cx,N ;N у cx go: mov dl,mas[si] ;first byte to the dl inc dl ;increment dl mov mas[si],dl ;return dl tj the array


Скачать презентацию на тему Lection 5. Arrays можно ниже:

Похожие презентации