简体   繁体   English

我们如何在Smalltalk中跳转到不同的内存地址?

[英]How can we jump to different memory address in Smalltalk?

I am trying to build an assembly language interpreter in Smalltalk. 我正在尝试在Smalltalk中构建汇编语言解释器。 Is there any command if I want to jump to a different memory location? 如果要跳转到其他存储位置,是否有任何命令? Example: There is an array of the memory address from 1-10. 示例:内存地址的数组为1-10。

1 LDI 10     //Load 10 to a register 
2 XCH        //Exchange value with different register
3 LDI 20     // Load 20 to a register
4 ADD        //Add the values 10 and 20
5 JMP 1     //Jump to memory address 1
6 HLT

To jump from memory address 5 to address 1, is there any command? 要从内存地址5跳转到地址1,是否有任何命令?

If you are trying to model an assembly interpreter you need to represent several objects. 如果要为装配解释器建模,则需要代表几个对象。 At least you will need to have objects (ie, classes) for registers, instructions and memory. 至少您将需要具有用于寄存器,指令和存储器的对象(即类)。 In this design, a program (or routine) would be a sequence of instructions and your interpreter would have an instruction pointer ip that moves along the routine. 在这种设计中,程序(或例程)将是一系列指令,而您的解释器将具有沿例程移动的指令指针ip

At every position of the ip , the interpreter would have to "execute" the current instruction, which would result in modifications to the registers and or specific memory locations. ip每个位置,解释器将不得不“执行”当前指令,这将导致对寄存器和/或特定存储器位置的修改。

For instance, you start the interpretation by assigning 1 to ip . 例如,通过为ip分配1来开始解释。 Now you read the instruction with index ip , in this case: 现在,在这种情况下,您阅读带有索引ip的指令:

1. LDI 10

Then you have to send the #execute message to the instruction. 然后,您必须将#execute消息发送到指令。 In this case the execution assigns the value 10 to the object representing register I . 在这种情况下,执行将值10分配给代表寄存器I的对象。 Now you increment ip and repeat until you run out of instructions. 现在,您增加ip并重复,直到用完指令为止。

In this "simulation" of the processor the jmp instruction would be one of the easiest ones to interpret: it would simply change the value of the instruction pointer ip to the target location. 在处理器的这种“模拟”中, jmp指令将是最容易解释的指令之一:它将简单地将指令指针ip的值更改为目标位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM