1

I'm very new to assembly language and I'm trying to develop a procedure that finds the highest value in an integer array, but I keep getting the error "Illegal Memory Reference" on lines 85,86, and 87. How am I suppose to fix this? Also, will the code I have find the highest value in the array?

highVal dw ?
data dw 0,0,0,0,0
input dw ?
count dw 0 

findHigh proc
mov cx,0
mov bx,0

L3:
    mov count,cx
    mov si,count
    inc bx
    (85)mov highVal,data[si]
    (86)mov input,data[bx]
    (87)cmp highVal,input
    jle L3
    jg L4

L4: 
    mov ax, highVal
    ret

findHigh endp
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Rogue_One
  • 21
  • 2

1 Answers1

0

That's a compile-time error, presumably from TASM?

All three nominated lines attempt to move data from somewhere in memory to somewhere else in memory. The 8086 doesn't support that. Only one operand may be a memory location.


Re: "will the code I have find the highest value in the array", that's not really on-topic for StackOverflow due to, at least, broadness. This isn't a code review site.

But since I've now read it anyway, off the top of my head:

  • your array is of words, which are two bytes long, so inc isn't sufficient;
  • you have count declared as a memory location, to which you repeatedly store the 0 you seeded cx with, and do nothing else with either;
  • the jg is redundant directly after a jle given that it jumps to the immediate-next statement; but
  • even if all those issues were resolved, you're exiting as soon as you find any value whatsoever higher than highVal. So you won't necessarily find the highest — if given the array 0, 1, 2, you'd exit upon seeing 1.

I think that at the very least you probably you want to seed cx with the array size, get rid of the first two movs and place a loop in front of where the ret currently is. That is, in addition to deciding what you really want in memory.

Tommy
  • 99,986
  • 12
  • 185
  • 204