2

Is it possible to move the memory address of a 32 bit register [esi] into an 8 bit AL register? Can you explain how does that work? Here is my code that displays an array of numbers via for loop of 1 to 6:

TITLE printing          (printarray.asm)                     (special.asm)

;This  
;Last updated 92.15.2016 Written by dr scheiman
INCLUDE Irvine32.inc
.data
   arrayb byte 1,2,3,4,5,6
   l dword lengthof arrayb
   space byte "     ",0
   x dword 3
.code
main PROC
    mov edx,offset space
    mov eax,0  ; clear ecx of garbage
    mov ecx, l ; loop counter 
    mov esi,offset arrayb ; start of the array's memory
    myloop:
       mov al,[esi] ;how do you move the memory address of a 32 bit into an 8 bit register?
       call writedec
       call writestring
       inc esi
     loop myloop
     call crlf

 exit

main ENDP

end main
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
jack black
  • 195
  • 1
  • 2
  • 11
  • This code loads a byte from the memory location whose address is the value in the ESI register. The pointer is 32-bit, but the data pointed to by the pointer is not. – icecreamsword Sep 21 '16 at 03:10
  • Thank you for answering. Can you put it in the big answering box so I can give you credit? Thank you – jack black Sep 21 '16 at 03:11
  • This is almost a duplicate of http://stackoverflow.com/questions/25129743/confusing-brackets-in-masm32, but that's talking more about how MASM infers operand-size when you use `[symbol]` instead of `[register]`. – Peter Cordes Sep 21 '16 at 03:25

1 Answers1

2

MASM infers the byte ptr [esi] operand-size based on the size of AL, and does an 8-bit load from the memory pointed to by the 32-bit pointer. The square brackets are a dereference for registers.

You could zero-extend those 8 bits to fill EAX with movzx eax, byte ptr [esi]. (Then you wouldn't need to zero eax earlier).

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847