Lab3 – 60-266-program in assembly language to initialize simple arrays
OBJECTIVES:
i) To learn how to write a simple program in assembly language.
ii) To become familiar with different data types.
iii) To learn to declare and initialize simple arrays.
Problem: i) Create and initialize an array of at least 5 unsigned word integers (myArray)
• Find the size of the array in number of bytes and store this value in a variable (myArraySize). NOTE: You must properly declare the variable first.
• Find the number of elements in the array and store this value in register ecx.
ii) Define a byte type variable (myByte1) and initialize it to a lowercase letter. Convert it to the corresponding uppercase letter and store the result in another variable (myByte2).
iii) Use DUP operator to create an array of 10 signed doubleword integers (myArray2) initialized to -76.
iv) Change the value of the 2nd element of the array to 11112222h. Store the upper 2 bytes of the second array element (new value) in register bx.
Hints:
1. Define the different arrays and variables in the data segement.
2: Use SIZEOF to find array size in bytes and LENGTHOF to find number of array elements.
3: Begin code segment
4: Move myByte1 to register al. Use ASCII table from book to covert to uppercase.
5: Store contents of al in myByte2.
6: Update and store the second element of myArray2
7. Use PTR operator to store upper two bytes into register bx.
Answer:
INCLUDE Irvine32.inc .data myArray WORD 10h, 22AAh, 35, 01111011b, 40h ; myArraySize DWORD ? myByte1 BYTE 'a' myByte2 BYTE ? myArray2 SDWORD 10 DUP (-76) .code main PROC mov myArraySize, SIZEOF myArray mov ecx, LENGTHOF myArray mov al,myByte1 ; al = 'a' = 61h sub al,20h ; al = 'A' = 41h mov myByte2,al ; store al in memory mov [myArray2 + TYPE myArray2], 11112222h ; change second element of myArray2 to 11112222h mov eax, [myArray2 + TYPE myArray2] ; check updated value mov bx, WORD PTR [myArray2+TYPE myArray2+2] ; move upper 2 bytes of second element of myArray2 into bx call DumpRegs exit main ENDP END main
Leave a reply