Threaded code: Difference between revisions

Content deleted Content added
Tags: Mobile edit Mobile app edit Android app edit
Pseudocode is unnecessarily confusing with multiple ++/-- operations on the same variable in an expression.
Line 69:
jump top
add:
addendaddend1 = *--sp // pointPop spthe to lasttop value savedoff onthe stack, follow it to copy that value out
*sp++addend2 = *--sp + addend // copyPop anothersecond value out of stack, add, copy sumoff intothe stack
*sp++ = addend1 + addend2 // Add the two values together and store the result on the top of the stack
jump top
</syntaxhighlight>
Line 98 ⟶ 99:
jump *ip++
add:
addendaddend1 = *--sp // pointPop spthe to lasttop value savedoff onthe stack, follow it to copy that value out
*sp++addend2 = *--sp + addend // copyPop anothersecond value out of stack, add, copy sumoff intothe stack
*sp++ = addend1 + addend2 // Add the two values together and store the result on top of the stack
jump *ip++
</syntaxhighlight>
Line 118 ⟶ 120:
 
<syntaxhighlight lang="c">
#define PUSH(x) (*sp++ = (x))
#define POP() (*--sp)
start:
ip = &thread // ip points to &pushA (which points to the first instruction of pushA)
Line 127 ⟶ 131:
...
pushA:
*sp++ = PUSH(A)
jump *ip++ // send control where ip says to (i.e. to pushB) and advance ip
pushB:
*sp++ = PUSH(B)
jump *ip++
add:
addendresult = *--spPOP() + POP()
PUSH(result)
*sp++ = *--sp + addend
jump *ip++
</syntaxhighlight>
Line 141 ⟶ 145:
 
<syntaxhighlight lang="c">
#define PUSH(x) (*sp++ = (x))
#define POP() (*--sp)
start:
ip = &thread
Line 152 ⟶ 158:
...
push:
*sp++variable_address = *ip++ // must move ip past operand address, since it is not a subroutine address
PUSH(*variable_address) // Read value from variable and push on stack
jump *ip++
add:
addendresult = *--spPOP() + POP()
PUSH(result)
*sp++ = *--sp + addend
jump *ip++
</syntaxhighlight>
Line 186 ⟶ 193:
jump *(*++ip) // advance ip in thread, jump through next indirect block to next subroutine
add:
addendaddend1 = *--sp
*sp++addend2 = *--sp + addend
*sp++ = *--spaddend1 + addendaddend2
jump *(*++ip)
</syntaxhighlight>
Line 211 ⟶ 219:
ret
add:
addendaddend1 = *--sp
*sp++addend2 = *--sp + addend
*sp++ = *--spaddend1 + addendaddend2
ret
</syntaxhighlight>
Line 243 ⟶ 252:
jump top
add:
addendaddend1 = *--sp
*sp++addend2 = *--sp + addend
*sp++ = addend1 + addend2
jump top
</syntaxhighlight>