Assembler labels with limited jump range

萝らか妹 提交于 2019-12-12 03:16:40

问题


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

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

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

JMP, 0x3F

//64 lines ahead

JMP, 0x5;

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:

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?


回答1:


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:

Could be replace by this code:

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


来源:https://stackoverflow.com/questions/26890249/assembler-labels-with-limited-jump-range

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!