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?
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
ipthat 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
1toip. Now you read the instruction with indexip, in this case:Then you have to send the
#executemessage to the instruction. In this case the execution assigns the value10to the object representing registerI. Now you incrementipand repeat until you run out of instructions.In this "simulation" of the processor the
jmpinstruction would be one of the easiest ones to interpret: it would simply change the value of the instruction pointeripto the target location.