2

This is a question identical to previous post. The objective is to take a BYTE array of 2, 4, 6, 8 ,10 and insert them into a DWORD array via a LOOP to display them. This is my latest attempt.

INCLUDE Irvine32.inc

.data

Array1 BYTE 2,4,6,8,10
Array2 DWORD 5 dup(0)

.code
main PROC


 mov esi, OFFSET Array1  ;esi = byteArray
 mov edi, OFFSET Array2  ;edi = dwordArray
 mov ecx, 5              ;counter of loop


 DAWG:
     mov eax, [esi]   ;attempting to use movzx causes errors
     mov [edi], eax
     inc esi
     add edi, 4
     loop DAWG

Any suggestions? Trying to figure it out with my bit (pun intended) of assembly knowledge. Thanks for reading.

4
  • 3
    This one works: movzx eax, byte ptr [esi]. Commented Sep 26, 2015 at 17:47
  • It indeed does. Thanks! For my knowledge, why does byte ptr make the statement work? Commented Sep 26, 2015 at 18:57
  • The assembler has to know, how much of [esi] is to be loaded into EAX, since there are different machine instructions for that purpose. byte ptr means: take one byte. Commented Sep 26, 2015 at 19:02
  • Gotcha. Thanks again! Commented Sep 26, 2015 at 20:02

1 Answer 1

3

1st solution as suggested by @rkhb is

DAWG:
 movzx eax, byte ptr [esi]
 mov   [edi], eax
 inc   esi
 add   edi, 4
 loop  DAWG

I would like to add this slightly more elegant solution:

 cld
 xor   eax, eax
DAWG:
 lodsb
 stosd
 loop  DAWG
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.