(c) Imagine that a new type of loop, called a mid-check loop, is to be added to the Jack language. The following is a ps
Posted: Thu Jun 02, 2022 8:28 am
(c) Imagine that a new type of loop, called a mid-check loop, is to be added to the Jack language. The following is a pseudo-code example: loop stml; exitif ( expr ) stm2; endloop The parts in bold are new keywords to be added to the language, stml and stm2 are pseudocode for Jack statements, and expr is pseudocode for a Jack expression. Zero or more statements may be written before the exit-check (exitif) and zero or more statements may be written after the parenthesised exit-check expression. The mid-check loop has the following execution characteristics: • The statements (if any) before the exit-check are executed. • The expression in the exit-check is evaluated. If the expression evaluates to true then the loop exits and control continues with whatever follows the loop body. If the expression evaluates to false then the statements (if any) following the exit-check are executed. • Once any statements following the exit-check have been executed, control returns to the statements (if any) preceding the exit check. In other words, the iteration repeats. The following pseudo-code example is to be translated to VM code: loop stml; exitif ( expr ) stm2; endloop The VM instruction set provides three instructions to manage flow-of- control: label, goto and if-goto. Assuming that in the translation to VM code of the example loop the translations of the two statements and the one expression appear in same order in the VM code as in the source code. complete the following outline