Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
2
software
Problems
Algorithms
Prog. Lang & Interfaces
H/w – s/w interface Instruction Set Architecture
Microarchitecture (Organization)
hardware
Circuits
Devices (Transistors)
Bits
..
call f1
..
Call 1
call f1
Call 2
..
Must save if routine will clobber a value that program may need
How to save?
• Store the needed registers in memory before the routine
starts
– Remember that JSR/JSRR/TRAP will overwrite R7
– Most instructions also overwrite CCRs, but LC3 gives no
instruction to save those aside, so program should not
expect old CCRs to be available
– ADD ..
– JSR .. (ADD's CCRs killed by JSR, so not seen by Brzp)
– Brzp .. won't work
• Load registers back from memory when the routine is done
© 2009 Vijaykumar ECE495K Lecture Notes: Chapter 9 12
Who saves aside program registers?
String length
• Input: sequence of characters terminated by NUL (ASCII 0)
• Output: length of string
• We’ll use R0 as the base address of the input string and
also as the length field
Let’s write out the “algorithm/pseudocode/flowchart”for the
routine first
Set length to 0
Is current string address pointing at NUL?
• If so, return length
Length = 0
H e l l o w o r l d !
Set length to 0
Is current string address pointing at NUL?
• If so, return length
• Else, increment length and string pointer; repeat
Length = 1
H e l l o w o r l d !