I have a little puzzle that I cannot get my old head around.
I have a data table :-
data db 10
db 12
db 21
etc
Now if I access the data like so:-
mov al,data[1] al then contains 10, but if I place 1 in a register (ebx) & access it like this:-
mov al,data[ebx] al contans garbage, to get it to work OK I have to use :-
mov al,data[ebx-1] al then contains 10.
To me mov al,data,[ebx-1] is the same as mov al,data[0] which doesn't exist.
Can anyone shed any light on this because I'm totally confused :dazzled:
Here are two variants that work as expected:
include \masm32\include\masm32rt.inc
.data
MyData db 10
db 12
db 21
.code
AppName db "Masm32:", 0
start:
xor ebx, ebx
mov al, MyData[ebx]
movzx eax, al
print str$(eax), " for MyData[ebx] with ebx=0", 13, 10
movzx eax, MyData[ebx]
print str$(eax), " for MyData[ebx] with ebx=0", 13, 10
exit
end start
QuoteNow if I access the data like so:-
mov al,data[1] al then contains 10, but if I place 1 in a register (ebx) & access it like this:-
no - AL will contain 12 :bg
if you want the first element, you want to use MOV AL,data[0]
or
mov ebx,offset data
.
.
.
mov al,ebx[0]
or
mov ebx,0
.
.
.
mov al,data[ebx]
Thanks for your replies, I had a feeling that the first element was at offset zero but I couldn't get it to work. Your replies confirmed this so I concluded that there was something wrong with my data in some way. I fired up Olly & looked at my data discovering that it was one byte out compared to what I was seeing on screen, so I loaded up a backup copy & guess what, it works as it should. Why it assembled differently to what I could see in qeditor I've no idea, it's almost as if there was a hidden byte at the start of the data, but anyway it's OK now :bg