This preview shows pages 1–2. Sign up to view the full content.
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=0N
POSITIVE:
SQUARE=1
LOOP:
IF SQUARE*SQUARE>N GOTO FINISH
SQUARE=SQUARE+1
GOTO LOOP
FINISH:
WRITE (SQUARE1)*(SQUARE1)
HALT
end
e
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)).
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
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '08
 Kay

Click to edit the document details