8-m - BME 303 Lecture 19 Exam #2 April 12 (two weeks from...

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

View Full Document Right Arrow Icon
1 BME 303 Lecture 19 • Exam #2 – April 12 (two weeks from today) – Covers all of module 2 (Chapters 5-10, lectures 12-20) – Review lecture next Tuesday • Today: Stacks
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Note for Monday section • Minor revisions to homework set posted (as announced) – primarily changes to 8.5 • Problem 8.2 will be extra credit – If you’re one of the 4 people who started 8.2 before I announced that (and Gabe and I know who you are), you can finish 8.2 and skip 8.4 instead. • Revised version ready for Tues. – Thurs. sections
Background image of page 2
3 Keyboard Input Note • Enter is represented in LC-3 as newline character (‘\n’, ASCII x0A), not carriage return character (‘\r’, ASCII x0D) as I stated last time Output TRAP routine Note • OUT does in fact preserve contents of R0 • Therefore code like this will work: GETC OUT ; echo character to display ; use R0, still value gotten from input
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Subroutine decomposition • Take every opportunity to make sub-tasks into subroutines. – Make program easier to understand – Might be useful later • Example: left rotate program – I wrote a separate routine that just left rotated by 1 bit, then called it from within a loop in the main body of the program – You don't have to do it this way, but it's a sensible decomposition
Background image of page 4
5 Loop Testing • Loops – where to do test? – At beginning of loop (top) – standard structured programming construct – At end of loop (bottom) – easier to code in assembly language • Guideline: – If loop body might never be executed (empty string, array, etc.), you must test at the top – If loop body should always be executed at least once , you must test at the bottom
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Loop Testing Top Test: LOOP_TOP <set condition codes as appropriate> BRccc AFTER_LOOP ; branch if loop done <body of loop> BR LOOP_TOP AFTER_LOOP <program continues> Bottom Test: LOOP_TOP <body of loop> <set condition codes as appropriate> BRccc LOOP_TOP ; branch if loop not done <program continues>
Background image of page 6
7 Common Errors • PUTS must have address in R0, not contents of location at that address MY_STRING .STRINGZ “a string\n” ; This works: LEA R0, MY_STRING PUTS ; This doesn’t: LD R0, MY_STRING PUTS
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Common Errors • Leaving data in the middle of program Don’t do this: LD R1, NEG_NL NEG_NL .FILL xFFF6 ADD R2, R0, R1 • You can actually get away with .STRINGZ data in midst of program: LEA R0, MY_STRING MY_STRING .STRINGZ “a string\n” PUTS – Why? – . . . but it’s very bad style! Don’t do it!
Background image of page 8
9 Debugging • Can help to use “Randomize Machine” menu item before loading program – easy to overlook changes when things are all zero to start with • Step by step execution – very helpful – three commands: “Step Over”, “Step Into”, “Step Out”
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 Stacks (chapter 10)
Background image of page 10
Physical Stacks • Tray or dish storage in a cafeteria line • Coin storage in an automobile armrest • First quarter out is the last quarter in. • Key characteristic: Last In, First Out
Background image of page 11

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

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

This note was uploaded on 09/06/2009 for the course BME 303 taught by Professor Ren during the Spring '08 term at University of Texas.

Page1 / 52

8-m - BME 303 Lecture 19 Exam #2 April 12 (two weeks from...

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

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