



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth analysis of memory addressing, specifically the difference between byte and word addressing, and the importance of alignment. Additionally, it covers instruction support for functions, including the use of jal and jr instructions, and the concept of nested procedures. The document also touches upon the organization of memory and the rules for procedures, including register conventions.
Typology: Slides
1 / 27
This page cannot be seen from the preview
Don't miss anything!




















Called the “address” of a word
Computers needed to access 8-bit bytes as well as words (4 bytes/word)
Today machines address memory as bytes, hence word addresses differ by 4 Memory[0], Memory[4], Memory[8],
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
... 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= 1012 j sum #jump to sum 1016 ...
2000 sum:add $v0,$a0,$a 2004 jr $ra # new instruction
Instruction Support for Functions
jr register
Nested Procedures
0x40 0000
0x1000 0000
0x7fff ffff
Reserved
Stack segment
Dynamic data Static data
Text segment
Data segment
The memory is byte addressed. If you want to step word by word through the memory, then you have to increase your “pointer” each time by 4.
C memory Allocation
∞
Address
$sp stack pointer
used space in the stack.
space we need and then fill it with info.
int sumSquare(int x, int y) {
return mult(x,x)+ y;
° }
°Compile by hand
sumSquare: addi $sp, $sp, -8 #space on stack sw $ra, 4($sp) #save ret addr sw $a1, 0($sp) # save y add $a1, $a0, $zero # mult(x,x) jal mult # call mult
jr $ra
you will call)! So what are they? Return address $ra Arguments $a0, $a1, $a2, $a Return value $v0, $v variables $s0, $s1, … , $s
needs to know which registers may have changed and which are guaranteed to be unchanged.
° Register Conventions: A set of generally
accepted rules as to which registers will be unchanged after a procedure call (jal) and which may be changed.