3

I am studying for an exam and have found no examples yet similar to this one.

I can see that mov al, '*' is moving a character into a register but I am uncertain as to what addressing mode is being used for this particular function.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Amy Krypto
  • 31
  • 3
  • 1
    Immediate (it's not really an addressing since nothing is addressed). – Jester Aug 06 '18 at 19:49
  • 3
    The assembler will convert the character in its encoding (usually ASCII) to numeric value (asterisk is represented by [value `42`](http://www.asciitable.com/) and because target is `al`, the numeric value is truncated to 8 bits - all ASCII codes do fit into 7 bits, so there's no truncation needed, but hypothetically, would your assembler operate in other encoding, the resulting value may be 16 bit (like for UCS2 encoding) or even with variable byte length (UTF8). So the resulting machine code is identical to `mov al,42`, but at source level the "character" gives more context to source reader. – Ped7g Aug 06 '18 at 20:37
  • 2
    @Ped7g as written in the title, it's `mov al, ' * '`, so you will in fact get `mov al, 32` because the first character in the character constant is a space. As you say, it's truncated to the operand size. I assumed this wasn't intended so I put `mov al, '*'` in the question body. – Peter Cordes Aug 07 '18 at 04:35
  • @PeterCordes I thought it was just avoidance of italics by somebody not aware of possibility of escaping the asterisk with backslash, but actually the single asterisk in topic is harmless... it would be helpful if the OP would clarify if it was `al, '*'` or really the variant with spaces (I find it hard to believe). Also it may have been copy-written manually from book/paper (not from source editor), without the OP realizing there's no space between apostrophes and asterisk... Hard to tell, but other people will unlikely search for literally `'*'`, so it probably doesn't matter. – Ped7g Aug 07 '18 at 18:26

1 Answers1

2

When you move a literal into a register, it's known as Immediate Mode.

Here's a useful reference that defines the most commonly used modes in processors, using the MIPS instruction set as the example.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
David Hoelzer
  • 15,862
  • 4
  • 48
  • 67