MIPS 装配标签 [英] MIPS Assembly Labels

查看:69
本文介绍了MIPS 装配标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MIPS 的汇编会读取每个标签吗?忽略任务和语法,我只是快速地把一些东西放在一起.

Does assembly for MIPS read every label? ignore the task and syntax, I just put something together quick.

add reg3, reg1, $zero
add reg1, reg1, reg2
beq reg1, reg3, BRANCH1      #reg2 contents are zero
bne reg1, $zero, BRANCH2     #reg1 doesn't equal zero
BRANCH1: add returnReg, reg1, $zero
BRANCH2: add returnReg, reg2, $zero
jr returnAddress

这是否会逐行读取,包括标签,除非它们被跳过?例如,除非 reg1 的内容为零,否则 BRANCH1 是否会每次都执行?

would this read line-by-line, including the labels, unless they were jumped over? For instance, would BRANCH1 be executed every single time, unless the contents of reg1 are equal to zero?

来自维基:标签是让您的生活变得简单的东西.当你引用一段程序时,不必计算行数,只需给它一个名字您可以在循环、跳转和变量名称中使用它.标签不会出现在您的最终代码中,它们只是为了方便起见,这是典型 MIPS 汇编器为您提供的少数好处之一.它还使汇编程序的工作变得轻松,因为它现在可以轻松地重新定位和链接代码.如果您不知道这些是什么,请不要担心,以后会知道的.

From wiki: A label is something to make your life simple. When you reference a piece of your program, instead of having to count lines, you can just give it a name You use this in loops, jumps, and variable names. Labels don't appear in your final code, they're only there for convenience, one of the few perks you'll get from the typical MIPS assembler. It also makes life easy for the assembler, because it can now easily go around relocating and linking code. Don't worry if you don't know what those are, that'll come later.

由此,我认为标签只不过是一个行参考.这意味着跳过代码(使用 bne、beq、jr、j 等)是防止读取某一行上的指令的唯一方法.这是正确的想法吗?

From this, I take that labels are nothing more than a line reference. Which means that jumping around the code (using bne, beq, jr, j, etc.) is the only way to prevent an instruction on a certain line to be read. Is this correct thinking?

推荐答案

标签只是为了让您可以通过跳转引用该行.CPU 本身只会看到机器代码.代码中的任何注释也是如此.它们只存在于汇编程序中 - 然后将其转换为机器代码.

Labels are only so you can reference the line with a jump. The CPU itself will only see the machine code. The same is true of any comments in your code. They are only there in the assembler - this is then converted into machine code.

如果不想执行,则需要跳过一行.

You will need to jump over a line if you don't want it executing.

这篇关于MIPS 装配标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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