Ask Your Question
3

How can arrays be printed on MASM?

asked 2023-05-16 20:01:32 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-05-16 20:16:02 +0000

woof gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-16 20:01:32 +0000

Seen: 7 times

Last updated: May 16 '23