0

Hi I'm new to assembly currently coding in 32bit assembly and I'm trying to access an array I initialized.

This is the array

lookup: dd 0, 3, 6, 9, 2, 5, 8, 1, 4, 7

This is what I'm trying to accomplish

add     bh, [lookup+al*4]

al is the index I want to add to bh

The code in c would be

b += a[i];

(b is bh, array is lookup, and al is i)

Any advice on how to accomplish this would be awesome, thanks!

3
  • 1
    al*4 isn't valid when specifying an address. Use eax*4 instead (and make sure that the unused bits of eax are zeroed). Commented Feb 18, 2015 at 20:23
  • Thank you for your help! However now when I try to mov eax, al I get an invalid number of opcode and operands error Commented Feb 18, 2015 at 20:37
  • Nevermind I'm stupid, al are the lower bits of eax Commented Feb 18, 2015 at 21:06

1 Answer 1

1

As Michael indicated in the comments, you can't use al in an effective address. Instead, we'll zero-extend al into eax, and use it instead:

movzx   eax, al                   ; zero-extend 8-bit al into 32-bit eax
add     bh, [lookup + eax*4]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.