文字VS立即操作数 [英] Literals VS Immediate Operands

查看:56
本文介绍了文字VS立即操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本学期的系统软件课程中,我们正在学习组装程序和其他系统软件.在阅读本课程时,我遇到了文学主题.

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.

如果可以使用立即数操作数,为什么必须使用文字?是什么让他们与众不同?换句话说,什么时候使用文字,什么时候使用立即数?

推荐答案

立即操作数是可以将其编码为指令本身的文字值,例如

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

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

但是,您可能需要将文字值放入程序可能使用的数据结构或表中.您可以使用声明存储的汇编程序"psuedo-ops"来执行此操作:

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"

这与call语句中的隐式文字并没有什么不同:

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

           CALL   FOO

指的是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.

这篇关于文字VS立即操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆