Jul-10-2019, 11:34 PM
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?
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?