slide3 - Computer Architecture CPSC 321 E J Kim Addressing...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Computer Architecture CPSC 321 E. J. Kim Addressing: Byte vs. word • Every word in memory has an address , similar to an index in an array • Early computers numbered words like C numbers elements of an array: • Memory[0], Memory[1], Memory[2], … Called the “ address ” of a word Computer s needed to access 8-bit bytes as well as wor ds (4 bytes/wor d) Today machines addr ess memor y as bytes, hence wor d addr esses differ by 4 Memor y[0], Memor y[ 4 ], Memor y[ 8 ], Notes about Memory • Pitfall : Forgetting that sequential word addresses in machines with byte addressing do not differ by 1. • Many an assembly language programmer has toiled over errors made by assuming that the address of the next word can be found by incrementing the address in a register by 1 instead of by the word size in bytes. • So remember that for both lw and sw, the sum of the base address and the offset must be a multiple of 4 (to be word aligned ) More Notes about Memory: Alignment • MI PS requires that all words start at addresses that are multiples of 4 bytes Called Alignment : objects must fall on address that is multiple of their size. 0 1 2 3 Aligned Not Aligned Bytes in Word Word Location I nstruction Support for Functions ... sum(a,b);... /* a, b: $s0,$s1 */ } int sum(int x, int y) { return x+y; } address 1000 add $a0,$s0,$zero # x = a 1004 add $a1,$s1,$zero # y = b 1008 addi $ra,$zero,1016 #$ra=1016 1012 j sum #jump to sum 1016 ... 2000 sum:add $v0,$a0,$a1 2004 jr $ra # n ew instruction C M I P S I nstruction Support for Functions • Single instruction to jump and save return address: jump and link ( jal ) • Before: 1008 addi $ra,$zero,1016 #$ra=1016 1012 j sum #go to sum • After: 1012 jal sum # $ra=1016,go to sum • Why have a jal ? Make the common case fast: functions are very common. I nstruction Support for Functions • Syntax for jr (jump register): jr register • I nstead of providing a label to jump to, the jr instruction provides a register which contains an address to jump to....
View Full Document

This note was uploaded on 03/23/2011 for the course CPSC 350 taught by Professor Staff during the Spring '08 term at Texas A&M.

Page1 / 27

slide3 - Computer Architecture CPSC 321 E J Kim Addressing...

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

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