Starting from:

$29.99

CSE341 Lab 6-Arrays Solution


Arrays are consecutive memory bytes.
Syntax: array_name data_type values Example 1:
myarr db 10,45,49 myarr1 dw "hi this is me"
The combination of numbers and characters is also valid. They are stored as ascii values arrays are also saved in the data segment of the memory

Example 2:
Java Code: int[] a = new int[5];
Assembly:
a db 5 dup(?) variable data_type size duplication
dup(?) stands for filling the array with blank dup(3) stands for filling the array with 3
Store values using index: For storing values you must be more or less clear about addressing modes (which has been discussed in theory). SI, DI and BX are the pointers of DS.




Exampel 3:
Java Code:
int [] a = {1,2,3,4,5}; for (int i = 0;i<a.length;i++){
System.out.println(a[i]);
}
Assembly Code:
Using pointer
.data a db 1,2,3,4,5 .code mov cx,5 mov ah,2 lea si, a start: mov dl,[si] int 21h add si,1 loop start

Using Index
.data a db 1,2,3,4,5 .code mov cx,5 mov ah,2 mov si,0 start: mov dl,a[si] int 21h add si,1 loop start





Class Task:
1. int x = 0; while (x < 15){ System.out.println(x); x=x+3;
} Hint:
Define x like this:
x db 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
2. Repeat Problem 1 with x = x-3; increment now.
3. Use array to store the name (of fixed length) of the user as a sequence of characters.
Then, display the name.
4. By using the code of Problem 2, print the name in reverse order.
5. Take an array of size 5. Store random numbers. Then, take two more inputs from the user. First input being an index, i, of the array, the second being a random number, x. After this, add the given input, x, to the value of index, i, of the array.

Home Task
1. Take input the length of the user’s name. Then, take the name as input, and then display.
2. Take an array of size 5, then taking input from the user, sort the array in the ascending order.
3. Take three inputs from the user and find the maximum of the three numbers.

More products