How can we jump to different memory address in Smalltalk?

128 views Asked by At

I am trying to build an assembly language interpreter in 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 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?

1

There are 1 answers

0
Leandro Caniglia On

If you are trying to model an assembly interpreter you need to represent several objects. At least you will need to have objects (i.e., 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.

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.

For instance, you start the interpretation by assigning 1 to ip. Now you read the instruction with index ip, in this case:

1. LDI 10

Then you have to send the #execute message to the instruction. In this case the execution assigns the value 10 to the object representing register I. Now you increment ip and repeat until you run out of instructions.

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.