汇编标签有限的范围内跳 [英] Assembler labels with limited jump range

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

问题描述

我写一个简单的RISC处理器,它具有跳跃一个非常小的immiediate(7位带符号)的汇编。所有跳跃都计算方法是:

I am writing an assembler for a simple RISC processor which has a very small immiediate for jumps (7 bit signed). All jumps are calculated by:

PC = PC + IMMEDIATE + 1

,其中PC是指向下一个指令的程序计数器。

where PC is the program counter which points to the next instruction.

如果您需要提前跳超过64行你需要链式跳跃如下:

If you need to jump more than 64 lines ahead you need chained jumps as follows:

JMP, 0x3F

//64 lines ahead

JMP, 0x5;

这将有效地跳跃前进当前指令的70行。

This would effectively jump 70 lines ahead of the current instruction.

我的问题进来的时候,我们有标签:

My question comes in when we have labels:

JMP, label

//more than 64 lines ahead

label:

如何将汇编程序产生code这个?你就需要两个标签或将使汇编的两跳的吗?如果把在两跳它是如何知道的指令是不是提前64行?

How would the assembler generate code for this? would you need two labels or would the assembler put in two jumps for you? If it puts in two jumps how does it know if an instruction is not 64 lines ahead?

推荐答案

条件跳转不能再不是向前127个字节或128字节落后领先。无条件跳能跳更远。我猜你有一个条件跳转尝试过。如果你想有条件跳转到一个地方更远超过127个字节,写一个无条件跳转到那个地方,并插入一个条件跳转之前,将跳过其他跳转指令如果未满足的条件。例如,这code:

Conditional jumps can not lead further than 127 bytes forward or 128 bytes backward. Unconditional jumps can jump farer. I guess you tried it with a conditional jump. If you want to jump conditionally to a place farer than 127 bytes, write a unconditional jump to that place and insert a conditional jump before that will jump over the other jump instruction if the condition isn't fulfilled. For example this code:

je label

//more than 127 bytes ahead

label:

可能是这个code替换:

Could be replace by this code:

jne omit
jmp label
omit:
//more than 127 bytes ahead
label:

这篇关于汇编标签有限的范围内跳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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