CSE 109 Test 2 SPRING 2004

CSE 109 Test 2 SPRING 2004 - CSE 109 Test 2 Wednesday 14...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 109 Test 2 Wednesday 14 April 2004 >>>>>>>>>>>SUGGESTED ANSWERS 1. Write a Simple Language Program that reads in an integer and writes out the largest square less than or equal to the absolute value of the number. For example, if the number is 29 then the program would write out 25; if the number is -16 then the program would write out 16. ======================================================= READ N IF N>0 GOTO POSITIVE N=0-N POSITIVE: SQUARE=1 LOOP: IF SQUARE*SQUARE>N GOTO FINISH SQUARE=SQUARE+1 GOTO LOOP FINISH: WRITE (SQUARE-1)*(SQUARE-1) HALT end 2. Write Simple Machine code that corresponds to the following Simple Language Program. (Recall Simple Machine operators: halt(0), read(1), write(2), load(3), store(4), add(5), sub(6), mul(7), div(8), branchle(9), branchge(A), branch(B)). READ X IF X<=2 GOTO ONE WRITE 5 ONE: HALT end =========================================== 100 40B 30B 309 600 908 30A 200 0 2 5 3. Assume class Lex is a lexical analyzer that reads input from cin and returns one of the following (distinct) int constants:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/05/2008 for the course CSE 109 taught by Professor Kay during the Spring '08 term at Lehigh University .

Page1 / 3

CSE 109 Test 2 SPRING 2004 - CSE 109 Test 2 Wednesday 14...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online