2

I am learning how to program in Assembly and I have a clarification question. In my book, it makes quite the deal out of the importance of using the correct suffix in conjunction with the command. However, in class the teacher has only used the 'movl' operand. Is my teacher doing this for simplicity or have the 'movb' and 'movw' commands become obsolete in recent years? Is efficiency lost when using movl as opposed to movb on a char type for example? Will it even work? Thanks

update: I am talking about x86-64 assembly

Peter Cordes
  • 245,674
  • 35
  • 423
  • 606
jnel899
  • 563
  • 1
  • 6
  • 21
  • 2
    BTW, some processors can handle non-aligned data, but not all. Then again, if you parse a received message,... The fields are often not zero-padded... Or if you have a big array of, say, megabyte sized structures as elements, padding all bytes to 32-bit words DO have an effect. – turboscrew Oct 19 '14 at 22:22

2 Answers2

3

What kind of architecture is this question relating to?

On modern x86, for example, loading with mov[b/w] kills performance due to partial register updates (prevents register renaming/extends the dependency chain). Use movzx/movsx to zero/sign-extend into the full-sized register to prevent this.

EOF
  • 5,857
  • 2
  • 23
  • 45
  • 1
    Yes I am talking about x86 architecture. Just to clarify; movzx will extend the data to 32 bits via zero padding so that the data fully occupies the register? – jnel899 Oct 19 '14 at 22:33
  • 2
    @jnel899: yes. See also [Why doesn't GCC use partial registers?](https://stackoverflow.com/q/41573502) for details on writing partial registers on various microarchitectures. – Peter Cordes Jun 05 '18 at 07:48
1

It's quite comparable of using integers vs. characters in higher level languages. They are not obsolete, but in small examples it doesn't matter if small numbers are stored as 32-bit words or bytes. However, if you manipulate strings, I very highly recommend using bytes. (Or you might accidentally overwrite some neighbouring characters.)

turboscrew
  • 650
  • 4
  • 12
  • Very good point, I see how a mistake could easily be made. You also made a good point about how doing this with large structures could also go awry. – jnel899 Oct 19 '14 at 22:37