EXAMPLE OF ATOI WRITTEN ON ONE FLAT INSTRUCTION =============================================== int atoi(s) char s[]; { static int n = 0; int i; char c; for (c = *s; c >= '0' && c <= '9'; c = *++s) n = n * 10 + c - '0'; return(n); } Initial Stack RAM when invoked. Initial Static RAM when invoked. | | | | |---------------------------| |-------| | | | rp.02 | atoi.static.rpstack.02 |---------------------------| |-------| | | | rp.01 | atoi.static.rpstack.01 |---------------------------| |-------| | s (operand for atoi) | | 0 | atoi.static.n |---------------------------| |-------| | Return PIN ADDRESS | | #01 | atoi.static.entry.01 PIN ADDR |---------------------------| |-------| atoi.static.entry.01 holds the pin address #01 atoi.static.n holds the variable n initially 0 atoi.static.rpstack.01 holds atoi.static.rpstack.02 holds |-----------------| |-----------------| |'0' | |atoi.automatic.n | |-----------------| |-----------------| |atoi.automatic,c | |fetch using | |-----------------| |-----------------| |fetch using | |10 | |-----------------| |-----------------| |>= | |* | |-----------------| |-----------------| |break if false | |atoi.automatic.c | |-----------------| |-----------------| |'9' | |fetch using | |-----------------| |-----------------| |atoi.automatic.c | |+ | |-----------------| |-----------------| |fetch using | |'0' | |-----------------| |-----------------| |<= | |- | |-----------------| |-----------------| |&& | |NULL | |-----------------| |-----------------| |NULL | |-----------------| atoi.automatic.s holds the value of s for each invocation atoi.automatic.i holds the value of i for each invocation atoi.automatic.n holds the value of n for each invocation atoi.automatic.c holds the value of c for each invocation ============================================================================ Send Function 1 Send Fubction 2 PIN #01 PIN #02 | | |-------| |-------| | #03 | | #06 | |-------| |-------| Function Register 1 Function Register 2 |------------------------------| |-----------------------| |pop stack and save in | |fetch using data | |atoi.automatic.s | | | |------------------------------| |-----------------------| Open Data Register PIN #03 | |---------------| | atoi | | operand | | from stack | |---------------| CC1 PIN CC2 PIN CC3 PIN | | | |-------| |-------| |-------| | #02 | | #02 | | #02 | |-------| |-------| |-------| | < | | 0 | | > | |-------| |-------| |-------| =========================================================================== Send Function 1 Send Fubction 2 PIN #04 PIN #05 | | |-------| |-------| | #05 | | #09 | |-------| |-------| Fuction Register 1 Function Register 2 |--------------------------| |------------------------------| |save in | |execute Reverse Polish | |atoi.automatic.c | |atoi.static.rpstack.01 | |--------------------------| |------------------------------| Open Data Register PIN #06 | |---------------| | | | *s | | | |---------------| CC1 PIN CC2 PIN CC3 PIN | | | |-------| |-------| |-------| | #04 | | #04 | | #04 | |-------| |-------| |-------| | < | | 0 | | > | |-------| |-------| |-------| ============================================================================ Send Function 1 Send Fubction 2 PIN #07 PIN #08 | | |-------| |-------| | #12 | | | |-------| |-------| Function Register 1 Function Register 2 |-----------------------| |------------------| |execute Reverse Polish | | | |atoi.static.rpstack.02 | | | |-----------------------| |------------------| Open Data Register PIN #09 | |----------------| | | | c>='0'&&c<='9' | | | |----------------| CC1 PIN CC2 PIN CC3 PIN | | | |-------| |-------| |-------| | #07 | | #16 | | #07 | |-------| |-------| |-------| | < | | 0 | | > | |-------| |-------| |-------| ============================================================================ Send Function 1 Send Fubction 2 PIN #10 PIN #11 | | |-------| |-------| | #11 | | #13 | |-------| |-------| Function Register 1 Function Register 2 |------------------------| |-----------------| |save in | |increment | |atoi.automatic.n | |atoi.automatic.s | |------------------------| |-----------------| Open Data Register PIN #12 | |---------------| | | | n*10+c-'0' | | | |---------------| CC1 PIN CC2 PIN CC3 PIN | | | |-------| |-------| |-------| | #10 | | #10 | | #10 | |-------| |-------| |-------| | < | | 0 | | > | |-------| |-------| |-------| ============================================================================ Send Function 1 Send Fubction 2 PIN #13 PIN #14 | | |-------| |-------| | #15 | | #05 | |-------| |-------| Function Register 1 Function Register 2 |------------------------| |---------------------| |fetch using | |save in | |atoi.automatic.s | |atoi.automatic.c | |------------------------| |---------------------| Open Data Register PIN #15 | |---------------| | | | *++s | | | |---------------| CC1 PIN CC2 PIN CC3 PIN | | | |-------| |-------| |-------| | #14 | | #14 | | #14 | |-------| |-------| |-------| | < | | 0 | | > | |-------| |-------| |-------| ============================================================================ Send Function 1 Send Fubction 2 PIN #16 PIN #17 | | |-------| |-------| | NULL | | | |-------| |-------| Function Register 1 Function Register 2 |----------------------------| |----------------------| |pop stack to temp | | | |push using atoi.automatic.n | | | |RETURN usimg temp | | | |----------------------------| |----------------------| Open Data Register PIN #18 | |---------------| | | | | | | |---------------| CC1 PIN CC2 PIN CC3 PIN | | | |-------| |-------| |-------| | | | | | | |-------| |-------| |-------| | < | | 0 | | > | |-------| |-------| |-------| ============================================================================ |