1

First of all, I use MASM615 as my compiler and use Irvine32.inc library. So I need to make a program using masm615 irvine32.inc to ask user to input an integer and save it to array. To stop input from user integer, user must type -1

INCLUDE Irvine32.inc
.data
ArrayInteger DWORD ?
.code
main PROC
mov esi,0
L1:
call ReadInt
L2:
cmp -1,eax
je EndLoop
mov ArrayInteger[esi * 4],eax
inc esi
jmp L1

EndLoop:
;rest of my code

So when ever i try to output my array that have been saved, it output gibberish or just straight crash. So my main question is, How do i declare an unknown Size/Elements array. sorry for my bad code, this is for my homework.

Astra99
  • 11
  • 1
  • 2
    You can't. The assembler and linker have to know exactly how large everything is in order to build the program. So you either choose a fixed maximum size (and write code to check at runtime that it isn't exceeded), or you call the operating system to allocate memory dynamically. – Nate Eldredge Apr 04 '21 at 15:52
  • `ArrayInteger DWORD ?` reserves space for one dword with unknown *value*. (Based on your question title, I thought that's what you were going to want, before I read the actual question. More clear might be "array of unknown size".) – Peter Cordes Apr 04 '21 at 17:38
  • You could build the array on the stack just by using `push` every time you read a number other than `-1`. (It would be indexed backwards, though, with the first element at the highest address) – Peter Cordes Apr 04 '21 at 17:42
  • Exact duplicate of [Create Dynamic dword array in x86 assembly](https://stackoverflow.com/q/29159296), but that has no answers. – Peter Cordes Apr 04 '21 at 18:00

0 Answers0