Please answer the following questions
Question
a) How big is the array VarY?
b) What are the values in array VarY after the code is executed?
c) What purpose does cmd1&cmd2 serve?
.data varX DWORD 9,8,7,6,5,4,3,2,1,0 varY DWORD (LENGTHOF varX) DUP(0) .code mov esi, offset varX ;cmdl mov esi, offset varY ;cmd2 mov esi, OFFSET varY + (SIZEOF varX)-4 mov edi, 4 mov ecx, LENGTHOF varX-1 L5: mov eax, varX[edi] mov [esi], eax add edi, 4 sub esi, 4 loop L5
Summary
-
- The user can not understand the assembly language because it is hard for him. Also, it is a low-level language.
- It is close to the machine.
- And it uses mnemonics like mov, add, sub.
- It uses operands like constant, count.
- We can also use Comments.
- There are different operations like mov, add, sub that we can perform on operands.
- Mov command is to move source operand to destination. Both the operands should be of the same size.
- Add command adds source to destination.
- Subtract command subtracts source from the destination.
Explanation
There are different data types in assembly language, some commonly used are:-
-
- BYTE, SBYTE -8-bit unsigned integer; 8-bit signed integer – it takes 1 byte
- WORD, SWORD 16-bit unsigned & signed integer – it takes 2 bytes
- DWORD, SDWORD 32-bit unsigned & signed integer – it takes 4 bytes
DUP operator-
We have used the DUP operator to allocate (create space for) an array or string. In other words, the DUP operator allows multiple initializations to the same value. For uninitialized data, we use (?) in DUP operator. For example- marks DW 8 DUP (0) makes an array named marks and allocates space for 8 elements with value 0.
DWORD is a double word that takes 4 bytes. We use DUP to initialize the memory.
Here, an array name is var2, and in this array, we have created a memory space for 2 elements with a value 5, then we have created a memory space with 12 values, and then we have created a 5*4 matrix with value 10.
The size(in no. of bytes) in our high-level programming languages like C/C++ can be calculated using sizeof the operator.
The size(in no. of items) in our high-level programming languages like C/C++ can be calculated using the size/length operator.
Offset tells the position in the array access. By default, it contains starting position/element.
Firstly, two arrays varX and vary are created of same length(10) and varX is initialized as {9,8,7,6,5,4,3,2,1,0} and vary has {0,0,0,0,0,0,0,0,0,0}.
Then, we have moved the first element of varX (i.e. 9) to register esi.
Then, esi contains the first element of varY(i.e. 0).
Then, esi contains 0 + 4 * 10 – 4 i.e. 36 positions ahead in vary which is 0.
Now edi register contains value 4 and ecx register contains 9.
In L5:
Register eax contains varX[4] which is 8.
Move value of register eax i.e. 8 to position 36 of y which makes vary as {0,0,0,0,0,0,0,0,0,8}
Then add 4 to edi and subtract 4 from esi.
Move 7 to 32 position of y, then move 6 to 28 position, 5 to 24 position, 4 to 20 position, 3 to 16 position, 2 to 12 position, 1 to 8 position and 0 to 4 position which makes vary as :- {0,0,1,2,3,4,5,6,7,8}.
-
-
- The array is of size 40 bytes and contains 10 elements.
- Value of varY: {0,0,1,2,3,4,5,6,7,8}.
- cmd1 means the result of 1st command to be stored in esi variable and cmd2 means the result of 2nd command to be stored individually and simultaneously.
-
Also read, Consider the following directed graph G as shown in Figure 2