Follow the instructions below to create a full running Assembly program:
Create a WORD sized array with 5 elements of A2D5h using the DUP operator. Move the OFFSET of this array into register ESI. Move the number of elements in the array initialized using the LENGTHOF instruction and move it into ECX as your loop counter.
Create a LOOP that adds the value 1F33h to each element. Traverse through the array by adding the size of each element to the ESI using the instruction TYPE.
Using instructions, MOVZX and M OVSX, move an element in the array into an appropriate sized register. After perform an swap of these two registers using the instruction XCHG. Lastly, utilize the instruction PTR to move an element from the array to a DWORD sized register.
SECTION . DATA
ARR DWORD 5 DUP(A2D5h)
ARR_SIZE EQU $ -ARR ; gives number of elements in which array.
SECTION .TEXT
global MAIN; must be declared for linker ( ld)
MAIN:
MOV ESI, ARRAY1 ; moves the offset of the array into ESI
MOV ECX, ARR_SIZE ; mov array size into ecx to act as the loop counter.
MOV EBX, 1F33h. Storing the data to be added in EBX.
SUM_UP:
ADD [ESI],EBX ;adding each element of the array with 1F33h.
ADD ESI,1 ; increment array address to pont the next element in the array.
DEC ECX ; Decrement loop counter.
JNZ SUM_UP ;jump to sum_up if counter not equal to zero.
MOVZX EAX, [ESI] ; moving array element into 32 bit register.
MOV EBX,[ESI-4] ; moves the previous array element to EBX.
XCHG EAX,EBX ;swap value in EAX with EBX
MOV EAX,DWORD PTR[ARR] ; An element of the array is moved EAX using PTR operator.
Get Answers For Free
Most questions answered within 1 hours.