Python Forum
How to create an 'interpreter of assembler'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create an 'interpreter of assembler'
#1
I’m doing an exercise which stores data in strings in a list. Each string contains a command. The list is meant to be interpreted in order of the strings. There just so happens to be a command which tells you to repeat a number of steps based on its location in the list.

For example:

simple_assembler(['mov a 5','inc a','dec a','dec a','jnz a -1','inc a'])
in the string with ‘jnz’, the -1 tells us to move one step backwards until a = 0. So I’m trying to write a program that can repeat iteration. I tried calling the function within the function under a while statement, but I think it resets each character’s value.

Let me explain the reasoning:

in the first step ‘mov a 5’, a becomes 5
so a=5
Second step ‘inc a’, which means increase a by 1
so a = 6
third and fourth step: decrease a by one
so ‘a = 4’
fifth step ‘jnz a -1’ which means go back one step and repeat it until a = 0
last step:
a = 1

So how do we tell the program to repeat a step?
Reply
#2
What did you try? Could you provide any code?
Reply
#3
You should have a pointer (an index) that tells you where you are in the program. Normally, this would be incremented by one after each command, to move you to the next command. However, branching commands like 'jnz' would do something else with the pointer, in this case move it back one instead of moving it forward one.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020