Today and probably the rest of the week I'm going to start working on the for next routine. I'm going to model it after Gates/Woz stack method of pushing the counter and start pointers on a stack, and popping them off every time a loop is done.
My plan of attack is going to be:
Get the next variable address and push it on the stack. (for a = 1 to 10 step 1. would be address of a)
Get beginning value (1) and assign it to variable
Get ending value (10) and push on to stack
Get step value (1) and push. if no step assume 1?
Get address of loop start and push.
Update stack pointer.
So every block is 8 bytes
00 01 varL varH
02 03 endL endH
04 05 stepL stepH
06 07 nxtL nxtH
when a next token is encountered
pop and store in registers: next address, step val, end val, var ptr.
add step val to var and compare.
if equal of higher branch out. update stack pointer
if lower push everything back (or just update pointer) and branch to beginning.
I need to handle negative case (for a= 10 to 0 step -1). Maybe a test for negative on step value switches the compare.
Ok, time to go to my day job (I'm a cook for the UCSC dining halls ;) )
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.