Literals VS Direct Operands

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

There was a comparison between literals and direct operands, which stated that the only difference between them was that literals were not assembled as part of the instruction, whereas direct operands.

Why should we use literals if we can use immediate operands? What makes them different? In other words, when to use literals and when to use direct operands?

+4
source share
1 answer

Immediate operands are literal values ​​that you can encode for the instructions themselves, for example,

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

But you may have to put literal values ​​in the data structures or tables that your program can use. You are using the psuedo-ops assembler, which declares the repository for this:

          DW      17     ; define a word containing the literal 17

Some literals, in particular text strings, almost never fit into the immediate field (there are not enough bits in the direct field), so they really cannot be included in your program as immediate values ​​of commands:

    XYZ    DC       "I am a duck."

When this happens, you will usually find instructions that reference the declared data through its label as an implicit immediate value that is not literal:

           MOV    R1, XYZ

- :

           MOV    R1,  "A"

, :

           CALL   FOO

FOO:

     FOO:  MOV   R1, 17
           RETURN

, .

+5

Source: https://habr.com/ru/post/1530282/


All Articles