How to Declare array in Assembly languages emu8086
What is array? We already know the answer. An array is a collective name given to a group of similar quantities. Like other programming languages, in assembly there are some methods to declare an array. Common things are there will be a name of the array, it's data type, it's length and it's initial value. Usually in assembly language we use two types of data 'DB' for Data Byte and 'DW' for Data Word. To know more about Variable declaration in assembly language you can read the article from there Register and Variable Declare. Now let's see about array.
As I have told before, there are several methods for declaring an array in assembly language. The very common method to declare an array in emu 8086 is
Here, ’My_Array’ is The Name of array and DB (Data Byte), DW (Data Word) are it’s type and 100 means it’s number of index or length and ‘DUP(?)’ means value of all the index are initially null.
A simple assembly code is given below
Array_Name Data_Type Values For Example: My_Array DB 10,20,30,40,50 My_Array DW 10,20,30,40,50Here, ’My_Array’ is the name of the array and DB (Data Byte), DW (Data Word) are it’s type. It depends on you that which type of data you want to store in your array. The last thing is assigning value in array or initial value of array. It is pre declared array. Here we assign value in the declaration time.
I can also develop a simple game for you in python
Now, If we want to declare the array without any initial value then it will beArray_Name Data_Type Number_Of_Index DUP(?)Example:
My_Array DB 100 DUP(?)
Here, ’My_Array’ is The Name of array and DB (Data Byte), DW (Data Word) are it’s type and 100 means it’s number of index or length and ‘DUP(?)’ means value of all the index are initially null.
A simple assembly code is given below
.MODEL SMALL .STACK 100h .DATA ARR DB 1,2,3,4,5 ;array declaration .CODE MAIN PROC MOV AX,@DATA MOV DS,AX MOV CX,5 MOV SI,0 MOV AH,2 OUTPUT: MOV DL, ARR[SI] ADD DL, 30H ;convert to asking INT 21H INC SI LOOP OUTPUT MAIN ENDP END MAIN
Here, We are taking user input into array using loop.
Comments
Post a Comment