Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Literals VS Immediate Operands

In the systems software course that I have this semester, we are being taught assemblers and other system software. While reading across the course I came across the topic of LITERALS.

There was a comparison between literals and immediate operands that said that the only difference between them is that literals are not assembled as a part of the instruction, whereas immediate operands are.

Why must we use literals if we can use immediate operands? What is it that makes them different? In other words in when to use literals and when to use immediate operands?

like image 559
Crystal Meth Avatar asked Mar 05 '14 17:03

Crystal Meth


1 Answers

Immediate operands are literal values you can encode into the instructions themselves, e.g.,

          MOV   R1,  17  ; move 17 as a value to R1

But, you may have need to put literal values into data structures or tables that your program may use. You use assembler "psuedo-ops" that declare storage to do this:

          DW      17     ; define a word containing the literal 17

Some literals, notably text strings, almost never fit into the immediate field (not enough bits in the immediate field), so really cannot be included in your program as instruction-immediate values:

    XYZ    DC       "I am a duck."

When this happens, you will typically find instructions that refer to the declared data via its label as an implicit immediate value, which is not a literal:

           MOV    R1, XYZ

An exception is an extremely short string literal:

           MOV    R1,  "A"

This isn't really different than the implicit literal in a call statement:

           CALL   FOO

which refers to the label on the FOO code:

     FOO:  MOV   R1, 17
           RETURN

Your assembler syntax may vary from this, but the principles stay the same.

like image 74
Ira Baxter Avatar answered Sep 29 '22 05:09

Ira Baxter