To print an array in MASM, you need to loop through each element of the array and print it using the appropriate system call. Here is an example code to print an array of integers using the "WriteConsoleA" system call:
.DATA
myArray DWORD 1,2,3,4,5
myArraySize DWORD 5 ;total number of elements in the array
.CODE
main PROC
;print array
mov ecx, myArraySize ;set loop counter
mov esi, OFFSET myArray ;load array address
L1:
mov eax, [esi] ;load array element
invoke WriteConsoleA, OUTPUT_HANDLE, ADDR eax, SIZEOF eax, ADDR bytesRead, NULL ;print array element
add esi, TYPE DWORD ;increment array index
loop L1
;exit program
invoke ExitProcess, 0
main ENDP
END main
In this code, we define an array called "myArray" with 5 elements. We also define a variable "myArraySize" to keep track of the number of elements in the array. In the main procedure, we loop through each element of the array using the "ecx" register as a loop counter and incrementing the "esi" register to access each element of the array. We load each element of the array into "eax" register and use the "WriteConsoleA" system call to print it to the console. Finally, we exit the program using the "ExitProcess" system call.
Asked: 2023-05-16 20:01:32 +0000
Seen: 7 times
Last updated: May 16 '23