Upload
ellery
View
42
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Computer Architecture Discussion. Lecture # 4 Procedures. Question # 30. Procedures purpose. Procedures (subroutines) allow the programmer to structure programs making them : easier to understand and debug and allowing code to be reused - PowerPoint PPT Presentation
Citation preview
Procedures (subroutines) allow the programmer to structure programs making them rsaquo easier to understand and debug andrsaquo allowing code to be reused
Procedures allow the programmer to concentrate on one portion of the code at a timersaquo parameters act as barriers between the procedure
and the rest of the program and data allowing the procedure to be passed values (arguments) and to return values (results)
Main routine (caller) places parameters in a place where the procedure (callee) can access themrsaquo $a0 - $a3 four argument registers
Caller transfers control to the callee Callee acquires the storage resources needed Callee performs the desired task Callee places the result value in a place where
the caller can access itrsaquo $v0 - $v1 two value registers for result values
Callee returns control to the callerrsaquo $ra one return address register to return to
the point of origin
$0 No Change Always 0 $s0-$s7 Restore if you change Very
important thatrsquos why theyrsquore called saved registers If the callee changes these in any way it must restore the original values before returning
$sp Restore if you change The stack pointer must point to the same place before and after the jal call or else the caller wonrsquot be able to restore values from the stack
bull HINT -- All saved registers start with S
$ra Can Change The jal call itself will change this register Caller needs to save on stack if nested call
$v0-$v1 Can Change These will contain the new returned values
$a0-$a3 Can change These are volatile argument registers Caller needs to save if theyrsquoll need them after the call
$t0-$t9 Can change Thatrsquos why theyrsquore called temporary any procedure may change them at any time Caller needs to save if theyrsquoll need them afterwards
Suppose we want a procedure lsquosprodrsquo that returns x1y1 + x2y2
Abstractly we can think of this assprod(x1y1x2y2)
a = prod(x1y1)x1y1b = prod(x2y2)x2y2return add2(ab) a + b
Procedure lsquosprodrsquo calls lsquoprodrsquo and lsquoadd2rsquo
jal procAddressrsaquo causes $31 to contain the next address
So each time that a procedure is called (eg when lsquoprodrsquo is called inside lsquosprodrsquo)rsaquo $31 gets overwritten (lsquoclobberedrsquo)
so that the return address for the outer procedure is no longer available
Stacks can get us out of this problem
When a C program is run there are 3 important memory areas allocated
rsaquo Static Variables declared once per
program cease to exist only after execution completes Eg C globalsrsaquo Heap Variables declared dynamicallyrsaquo Stack Space to be used by procedure
during execution this is where we can save register values
A stack is used to store the sequence of return addresses when there are nested calls
The calling (outer) procedure rsaquo pushes address in $31 onto stackrsaquo calls the procedure ($31 contains return address)rsaquo pops stack to restore $31 (after procedure returns)
The called procedure before returningrsaquo if it has called another procedure it overwrites $31
with a pop from the stackrsaquo jr $31
bull Step-1 Pass the arguments1048766 The first four arguments (arg0-arg3)
are passed in registers $a0-$a31048766 Remaining arguments are pushed
onto the stack (in reverse order arg5 is at the top of
the stack) Step-2 Save caller-saved registers1048766 Save registers $t0-$t9 if they contain
live values at the call site bull Step-3 Execute a jal instruction
Step-1 Establish stack frame1048766 Subtract the frame size from the stack pointer subi $sp $sp ltframe-sizegt1048766 Typically minimum frame size is 32 bytes (8
words) Step-2 Save callee saved registers in the
frame1048766 Register $fp is always saved1048766 Register $ra is saved if routine makes a call1048766 Registers $s0-$s7 are saved if they are used Step-3 Establish Frame pointer1048766 Add the stack ltframe sizegt - 4 to the address in
$sp addi $fp $sp ltframe-sizegt - 4
Step-1 Put returned values in registers $v0 [$v1]
(if values are returned) Step-2 Restore callee-saved registers1048766 Restore $fp and other saved registers [$ra
$s0 - $s7] Step-3 Pop the stack1048766 Add the frame size to $sp addi $sp $sp ltframe-sizegt Step-4 Return1048766 Jump to the address in $ra jr $ra
f0 = 1 f-1 = -1fn = fn-1 + fn-2
f = 1 1 2 3 5 8 13 hellip
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
Main routine (caller) places parameters in a place where the procedure (callee) can access themrsaquo $a0 - $a3 four argument registers
Caller transfers control to the callee Callee acquires the storage resources needed Callee performs the desired task Callee places the result value in a place where
the caller can access itrsaquo $v0 - $v1 two value registers for result values
Callee returns control to the callerrsaquo $ra one return address register to return to
the point of origin
$0 No Change Always 0 $s0-$s7 Restore if you change Very
important thatrsquos why theyrsquore called saved registers If the callee changes these in any way it must restore the original values before returning
$sp Restore if you change The stack pointer must point to the same place before and after the jal call or else the caller wonrsquot be able to restore values from the stack
bull HINT -- All saved registers start with S
$ra Can Change The jal call itself will change this register Caller needs to save on stack if nested call
$v0-$v1 Can Change These will contain the new returned values
$a0-$a3 Can change These are volatile argument registers Caller needs to save if theyrsquoll need them after the call
$t0-$t9 Can change Thatrsquos why theyrsquore called temporary any procedure may change them at any time Caller needs to save if theyrsquoll need them afterwards
Suppose we want a procedure lsquosprodrsquo that returns x1y1 + x2y2
Abstractly we can think of this assprod(x1y1x2y2)
a = prod(x1y1)x1y1b = prod(x2y2)x2y2return add2(ab) a + b
Procedure lsquosprodrsquo calls lsquoprodrsquo and lsquoadd2rsquo
jal procAddressrsaquo causes $31 to contain the next address
So each time that a procedure is called (eg when lsquoprodrsquo is called inside lsquosprodrsquo)rsaquo $31 gets overwritten (lsquoclobberedrsquo)
so that the return address for the outer procedure is no longer available
Stacks can get us out of this problem
When a C program is run there are 3 important memory areas allocated
rsaquo Static Variables declared once per
program cease to exist only after execution completes Eg C globalsrsaquo Heap Variables declared dynamicallyrsaquo Stack Space to be used by procedure
during execution this is where we can save register values
A stack is used to store the sequence of return addresses when there are nested calls
The calling (outer) procedure rsaquo pushes address in $31 onto stackrsaquo calls the procedure ($31 contains return address)rsaquo pops stack to restore $31 (after procedure returns)
The called procedure before returningrsaquo if it has called another procedure it overwrites $31
with a pop from the stackrsaquo jr $31
bull Step-1 Pass the arguments1048766 The first four arguments (arg0-arg3)
are passed in registers $a0-$a31048766 Remaining arguments are pushed
onto the stack (in reverse order arg5 is at the top of
the stack) Step-2 Save caller-saved registers1048766 Save registers $t0-$t9 if they contain
live values at the call site bull Step-3 Execute a jal instruction
Step-1 Establish stack frame1048766 Subtract the frame size from the stack pointer subi $sp $sp ltframe-sizegt1048766 Typically minimum frame size is 32 bytes (8
words) Step-2 Save callee saved registers in the
frame1048766 Register $fp is always saved1048766 Register $ra is saved if routine makes a call1048766 Registers $s0-$s7 are saved if they are used Step-3 Establish Frame pointer1048766 Add the stack ltframe sizegt - 4 to the address in
$sp addi $fp $sp ltframe-sizegt - 4
Step-1 Put returned values in registers $v0 [$v1]
(if values are returned) Step-2 Restore callee-saved registers1048766 Restore $fp and other saved registers [$ra
$s0 - $s7] Step-3 Pop the stack1048766 Add the frame size to $sp addi $sp $sp ltframe-sizegt Step-4 Return1048766 Jump to the address in $ra jr $ra
f0 = 1 f-1 = -1fn = fn-1 + fn-2
f = 1 1 2 3 5 8 13 hellip
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
$0 No Change Always 0 $s0-$s7 Restore if you change Very
important thatrsquos why theyrsquore called saved registers If the callee changes these in any way it must restore the original values before returning
$sp Restore if you change The stack pointer must point to the same place before and after the jal call or else the caller wonrsquot be able to restore values from the stack
bull HINT -- All saved registers start with S
$ra Can Change The jal call itself will change this register Caller needs to save on stack if nested call
$v0-$v1 Can Change These will contain the new returned values
$a0-$a3 Can change These are volatile argument registers Caller needs to save if theyrsquoll need them after the call
$t0-$t9 Can change Thatrsquos why theyrsquore called temporary any procedure may change them at any time Caller needs to save if theyrsquoll need them afterwards
Suppose we want a procedure lsquosprodrsquo that returns x1y1 + x2y2
Abstractly we can think of this assprod(x1y1x2y2)
a = prod(x1y1)x1y1b = prod(x2y2)x2y2return add2(ab) a + b
Procedure lsquosprodrsquo calls lsquoprodrsquo and lsquoadd2rsquo
jal procAddressrsaquo causes $31 to contain the next address
So each time that a procedure is called (eg when lsquoprodrsquo is called inside lsquosprodrsquo)rsaquo $31 gets overwritten (lsquoclobberedrsquo)
so that the return address for the outer procedure is no longer available
Stacks can get us out of this problem
When a C program is run there are 3 important memory areas allocated
rsaquo Static Variables declared once per
program cease to exist only after execution completes Eg C globalsrsaquo Heap Variables declared dynamicallyrsaquo Stack Space to be used by procedure
during execution this is where we can save register values
A stack is used to store the sequence of return addresses when there are nested calls
The calling (outer) procedure rsaquo pushes address in $31 onto stackrsaquo calls the procedure ($31 contains return address)rsaquo pops stack to restore $31 (after procedure returns)
The called procedure before returningrsaquo if it has called another procedure it overwrites $31
with a pop from the stackrsaquo jr $31
bull Step-1 Pass the arguments1048766 The first four arguments (arg0-arg3)
are passed in registers $a0-$a31048766 Remaining arguments are pushed
onto the stack (in reverse order arg5 is at the top of
the stack) Step-2 Save caller-saved registers1048766 Save registers $t0-$t9 if they contain
live values at the call site bull Step-3 Execute a jal instruction
Step-1 Establish stack frame1048766 Subtract the frame size from the stack pointer subi $sp $sp ltframe-sizegt1048766 Typically minimum frame size is 32 bytes (8
words) Step-2 Save callee saved registers in the
frame1048766 Register $fp is always saved1048766 Register $ra is saved if routine makes a call1048766 Registers $s0-$s7 are saved if they are used Step-3 Establish Frame pointer1048766 Add the stack ltframe sizegt - 4 to the address in
$sp addi $fp $sp ltframe-sizegt - 4
Step-1 Put returned values in registers $v0 [$v1]
(if values are returned) Step-2 Restore callee-saved registers1048766 Restore $fp and other saved registers [$ra
$s0 - $s7] Step-3 Pop the stack1048766 Add the frame size to $sp addi $sp $sp ltframe-sizegt Step-4 Return1048766 Jump to the address in $ra jr $ra
f0 = 1 f-1 = -1fn = fn-1 + fn-2
f = 1 1 2 3 5 8 13 hellip
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
$ra Can Change The jal call itself will change this register Caller needs to save on stack if nested call
$v0-$v1 Can Change These will contain the new returned values
$a0-$a3 Can change These are volatile argument registers Caller needs to save if theyrsquoll need them after the call
$t0-$t9 Can change Thatrsquos why theyrsquore called temporary any procedure may change them at any time Caller needs to save if theyrsquoll need them afterwards
Suppose we want a procedure lsquosprodrsquo that returns x1y1 + x2y2
Abstractly we can think of this assprod(x1y1x2y2)
a = prod(x1y1)x1y1b = prod(x2y2)x2y2return add2(ab) a + b
Procedure lsquosprodrsquo calls lsquoprodrsquo and lsquoadd2rsquo
jal procAddressrsaquo causes $31 to contain the next address
So each time that a procedure is called (eg when lsquoprodrsquo is called inside lsquosprodrsquo)rsaquo $31 gets overwritten (lsquoclobberedrsquo)
so that the return address for the outer procedure is no longer available
Stacks can get us out of this problem
When a C program is run there are 3 important memory areas allocated
rsaquo Static Variables declared once per
program cease to exist only after execution completes Eg C globalsrsaquo Heap Variables declared dynamicallyrsaquo Stack Space to be used by procedure
during execution this is where we can save register values
A stack is used to store the sequence of return addresses when there are nested calls
The calling (outer) procedure rsaquo pushes address in $31 onto stackrsaquo calls the procedure ($31 contains return address)rsaquo pops stack to restore $31 (after procedure returns)
The called procedure before returningrsaquo if it has called another procedure it overwrites $31
with a pop from the stackrsaquo jr $31
bull Step-1 Pass the arguments1048766 The first four arguments (arg0-arg3)
are passed in registers $a0-$a31048766 Remaining arguments are pushed
onto the stack (in reverse order arg5 is at the top of
the stack) Step-2 Save caller-saved registers1048766 Save registers $t0-$t9 if they contain
live values at the call site bull Step-3 Execute a jal instruction
Step-1 Establish stack frame1048766 Subtract the frame size from the stack pointer subi $sp $sp ltframe-sizegt1048766 Typically minimum frame size is 32 bytes (8
words) Step-2 Save callee saved registers in the
frame1048766 Register $fp is always saved1048766 Register $ra is saved if routine makes a call1048766 Registers $s0-$s7 are saved if they are used Step-3 Establish Frame pointer1048766 Add the stack ltframe sizegt - 4 to the address in
$sp addi $fp $sp ltframe-sizegt - 4
Step-1 Put returned values in registers $v0 [$v1]
(if values are returned) Step-2 Restore callee-saved registers1048766 Restore $fp and other saved registers [$ra
$s0 - $s7] Step-3 Pop the stack1048766 Add the frame size to $sp addi $sp $sp ltframe-sizegt Step-4 Return1048766 Jump to the address in $ra jr $ra
f0 = 1 f-1 = -1fn = fn-1 + fn-2
f = 1 1 2 3 5 8 13 hellip
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
Suppose we want a procedure lsquosprodrsquo that returns x1y1 + x2y2
Abstractly we can think of this assprod(x1y1x2y2)
a = prod(x1y1)x1y1b = prod(x2y2)x2y2return add2(ab) a + b
Procedure lsquosprodrsquo calls lsquoprodrsquo and lsquoadd2rsquo
jal procAddressrsaquo causes $31 to contain the next address
So each time that a procedure is called (eg when lsquoprodrsquo is called inside lsquosprodrsquo)rsaquo $31 gets overwritten (lsquoclobberedrsquo)
so that the return address for the outer procedure is no longer available
Stacks can get us out of this problem
When a C program is run there are 3 important memory areas allocated
rsaquo Static Variables declared once per
program cease to exist only after execution completes Eg C globalsrsaquo Heap Variables declared dynamicallyrsaquo Stack Space to be used by procedure
during execution this is where we can save register values
A stack is used to store the sequence of return addresses when there are nested calls
The calling (outer) procedure rsaquo pushes address in $31 onto stackrsaquo calls the procedure ($31 contains return address)rsaquo pops stack to restore $31 (after procedure returns)
The called procedure before returningrsaquo if it has called another procedure it overwrites $31
with a pop from the stackrsaquo jr $31
bull Step-1 Pass the arguments1048766 The first four arguments (arg0-arg3)
are passed in registers $a0-$a31048766 Remaining arguments are pushed
onto the stack (in reverse order arg5 is at the top of
the stack) Step-2 Save caller-saved registers1048766 Save registers $t0-$t9 if they contain
live values at the call site bull Step-3 Execute a jal instruction
Step-1 Establish stack frame1048766 Subtract the frame size from the stack pointer subi $sp $sp ltframe-sizegt1048766 Typically minimum frame size is 32 bytes (8
words) Step-2 Save callee saved registers in the
frame1048766 Register $fp is always saved1048766 Register $ra is saved if routine makes a call1048766 Registers $s0-$s7 are saved if they are used Step-3 Establish Frame pointer1048766 Add the stack ltframe sizegt - 4 to the address in
$sp addi $fp $sp ltframe-sizegt - 4
Step-1 Put returned values in registers $v0 [$v1]
(if values are returned) Step-2 Restore callee-saved registers1048766 Restore $fp and other saved registers [$ra
$s0 - $s7] Step-3 Pop the stack1048766 Add the frame size to $sp addi $sp $sp ltframe-sizegt Step-4 Return1048766 Jump to the address in $ra jr $ra
f0 = 1 f-1 = -1fn = fn-1 + fn-2
f = 1 1 2 3 5 8 13 hellip
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
jal procAddressrsaquo causes $31 to contain the next address
So each time that a procedure is called (eg when lsquoprodrsquo is called inside lsquosprodrsquo)rsaquo $31 gets overwritten (lsquoclobberedrsquo)
so that the return address for the outer procedure is no longer available
Stacks can get us out of this problem
When a C program is run there are 3 important memory areas allocated
rsaquo Static Variables declared once per
program cease to exist only after execution completes Eg C globalsrsaquo Heap Variables declared dynamicallyrsaquo Stack Space to be used by procedure
during execution this is where we can save register values
A stack is used to store the sequence of return addresses when there are nested calls
The calling (outer) procedure rsaquo pushes address in $31 onto stackrsaquo calls the procedure ($31 contains return address)rsaquo pops stack to restore $31 (after procedure returns)
The called procedure before returningrsaquo if it has called another procedure it overwrites $31
with a pop from the stackrsaquo jr $31
bull Step-1 Pass the arguments1048766 The first four arguments (arg0-arg3)
are passed in registers $a0-$a31048766 Remaining arguments are pushed
onto the stack (in reverse order arg5 is at the top of
the stack) Step-2 Save caller-saved registers1048766 Save registers $t0-$t9 if they contain
live values at the call site bull Step-3 Execute a jal instruction
Step-1 Establish stack frame1048766 Subtract the frame size from the stack pointer subi $sp $sp ltframe-sizegt1048766 Typically minimum frame size is 32 bytes (8
words) Step-2 Save callee saved registers in the
frame1048766 Register $fp is always saved1048766 Register $ra is saved if routine makes a call1048766 Registers $s0-$s7 are saved if they are used Step-3 Establish Frame pointer1048766 Add the stack ltframe sizegt - 4 to the address in
$sp addi $fp $sp ltframe-sizegt - 4
Step-1 Put returned values in registers $v0 [$v1]
(if values are returned) Step-2 Restore callee-saved registers1048766 Restore $fp and other saved registers [$ra
$s0 - $s7] Step-3 Pop the stack1048766 Add the frame size to $sp addi $sp $sp ltframe-sizegt Step-4 Return1048766 Jump to the address in $ra jr $ra
f0 = 1 f-1 = -1fn = fn-1 + fn-2
f = 1 1 2 3 5 8 13 hellip
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
When a C program is run there are 3 important memory areas allocated
rsaquo Static Variables declared once per
program cease to exist only after execution completes Eg C globalsrsaquo Heap Variables declared dynamicallyrsaquo Stack Space to be used by procedure
during execution this is where we can save register values
A stack is used to store the sequence of return addresses when there are nested calls
The calling (outer) procedure rsaquo pushes address in $31 onto stackrsaquo calls the procedure ($31 contains return address)rsaquo pops stack to restore $31 (after procedure returns)
The called procedure before returningrsaquo if it has called another procedure it overwrites $31
with a pop from the stackrsaquo jr $31
bull Step-1 Pass the arguments1048766 The first four arguments (arg0-arg3)
are passed in registers $a0-$a31048766 Remaining arguments are pushed
onto the stack (in reverse order arg5 is at the top of
the stack) Step-2 Save caller-saved registers1048766 Save registers $t0-$t9 if they contain
live values at the call site bull Step-3 Execute a jal instruction
Step-1 Establish stack frame1048766 Subtract the frame size from the stack pointer subi $sp $sp ltframe-sizegt1048766 Typically minimum frame size is 32 bytes (8
words) Step-2 Save callee saved registers in the
frame1048766 Register $fp is always saved1048766 Register $ra is saved if routine makes a call1048766 Registers $s0-$s7 are saved if they are used Step-3 Establish Frame pointer1048766 Add the stack ltframe sizegt - 4 to the address in
$sp addi $fp $sp ltframe-sizegt - 4
Step-1 Put returned values in registers $v0 [$v1]
(if values are returned) Step-2 Restore callee-saved registers1048766 Restore $fp and other saved registers [$ra
$s0 - $s7] Step-3 Pop the stack1048766 Add the frame size to $sp addi $sp $sp ltframe-sizegt Step-4 Return1048766 Jump to the address in $ra jr $ra
f0 = 1 f-1 = -1fn = fn-1 + fn-2
f = 1 1 2 3 5 8 13 hellip
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
A stack is used to store the sequence of return addresses when there are nested calls
The calling (outer) procedure rsaquo pushes address in $31 onto stackrsaquo calls the procedure ($31 contains return address)rsaquo pops stack to restore $31 (after procedure returns)
The called procedure before returningrsaquo if it has called another procedure it overwrites $31
with a pop from the stackrsaquo jr $31
bull Step-1 Pass the arguments1048766 The first four arguments (arg0-arg3)
are passed in registers $a0-$a31048766 Remaining arguments are pushed
onto the stack (in reverse order arg5 is at the top of
the stack) Step-2 Save caller-saved registers1048766 Save registers $t0-$t9 if they contain
live values at the call site bull Step-3 Execute a jal instruction
Step-1 Establish stack frame1048766 Subtract the frame size from the stack pointer subi $sp $sp ltframe-sizegt1048766 Typically minimum frame size is 32 bytes (8
words) Step-2 Save callee saved registers in the
frame1048766 Register $fp is always saved1048766 Register $ra is saved if routine makes a call1048766 Registers $s0-$s7 are saved if they are used Step-3 Establish Frame pointer1048766 Add the stack ltframe sizegt - 4 to the address in
$sp addi $fp $sp ltframe-sizegt - 4
Step-1 Put returned values in registers $v0 [$v1]
(if values are returned) Step-2 Restore callee-saved registers1048766 Restore $fp and other saved registers [$ra
$s0 - $s7] Step-3 Pop the stack1048766 Add the frame size to $sp addi $sp $sp ltframe-sizegt Step-4 Return1048766 Jump to the address in $ra jr $ra
f0 = 1 f-1 = -1fn = fn-1 + fn-2
f = 1 1 2 3 5 8 13 hellip
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
bull Step-1 Pass the arguments1048766 The first four arguments (arg0-arg3)
are passed in registers $a0-$a31048766 Remaining arguments are pushed
onto the stack (in reverse order arg5 is at the top of
the stack) Step-2 Save caller-saved registers1048766 Save registers $t0-$t9 if they contain
live values at the call site bull Step-3 Execute a jal instruction
Step-1 Establish stack frame1048766 Subtract the frame size from the stack pointer subi $sp $sp ltframe-sizegt1048766 Typically minimum frame size is 32 bytes (8
words) Step-2 Save callee saved registers in the
frame1048766 Register $fp is always saved1048766 Register $ra is saved if routine makes a call1048766 Registers $s0-$s7 are saved if they are used Step-3 Establish Frame pointer1048766 Add the stack ltframe sizegt - 4 to the address in
$sp addi $fp $sp ltframe-sizegt - 4
Step-1 Put returned values in registers $v0 [$v1]
(if values are returned) Step-2 Restore callee-saved registers1048766 Restore $fp and other saved registers [$ra
$s0 - $s7] Step-3 Pop the stack1048766 Add the frame size to $sp addi $sp $sp ltframe-sizegt Step-4 Return1048766 Jump to the address in $ra jr $ra
f0 = 1 f-1 = -1fn = fn-1 + fn-2
f = 1 1 2 3 5 8 13 hellip
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
Step-1 Establish stack frame1048766 Subtract the frame size from the stack pointer subi $sp $sp ltframe-sizegt1048766 Typically minimum frame size is 32 bytes (8
words) Step-2 Save callee saved registers in the
frame1048766 Register $fp is always saved1048766 Register $ra is saved if routine makes a call1048766 Registers $s0-$s7 are saved if they are used Step-3 Establish Frame pointer1048766 Add the stack ltframe sizegt - 4 to the address in
$sp addi $fp $sp ltframe-sizegt - 4
Step-1 Put returned values in registers $v0 [$v1]
(if values are returned) Step-2 Restore callee-saved registers1048766 Restore $fp and other saved registers [$ra
$s0 - $s7] Step-3 Pop the stack1048766 Add the frame size to $sp addi $sp $sp ltframe-sizegt Step-4 Return1048766 Jump to the address in $ra jr $ra
f0 = 1 f-1 = -1fn = fn-1 + fn-2
f = 1 1 2 3 5 8 13 hellip
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
Step-1 Put returned values in registers $v0 [$v1]
(if values are returned) Step-2 Restore callee-saved registers1048766 Restore $fp and other saved registers [$ra
$s0 - $s7] Step-3 Pop the stack1048766 Add the frame size to $sp addi $sp $sp ltframe-sizegt Step-4 Return1048766 Jump to the address in $ra jr $ra
f0 = 1 f-1 = -1fn = fn-1 + fn-2
f = 1 1 2 3 5 8 13 hellip
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
f0 = 1 f-1 = -1fn = fn-1 + fn-2
f = 1 1 2 3 5 8 13 hellip
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
include ltstdiohgtint main (int argc char argv[]) int i int sum = 0 for (i = 0 i lt= 100 i = i + 1)
sum = sum + i i printf (The sum from 0 100 is dn sum)
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
The stepsrsaquo Software design is translated into source codersaquo Source code is entered using an editor making source filesrsaquo Source files are assembled or compiled producing object
filesrsaquo Object files are linked into an executable filersaquo Executable files are loaded into memory and then run
ExecutableObjectfilesAssemble
rsource
source
ProgramLoaded
Into memory
ResultOf
Careful Softwaredesign
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
Types of assembly lines Machine instruction
sw $ra20($sp) Pseudoinstruction
rsaquo Data-definition asciiz ldquoThe sum
fromrdquorsaquo Assembler directive
text globl main align 0
Labelbull mainbull loop
text
align 2
globl mainmain
subu $sp $sp 32
sw $ra 20($sp)
sd $a0 32($sp)
sw $0 24($sp)sw $0 28($sp)
looplw $t6 28($sp)
mul $t7 $t6 $t6
lw $t8 24($sp)
addu $t9 $t8 $t7
sw $t9 24($sp)
addu $t0 $t6 1sw $t0 28($sp)
ble$t0 100 loopla $a0 strlw $a1 24($sp)
jal printfmove$v0 $0
lw $ra 20($sp)
addu $sp $sp 32
jr $ra
data
align 0str
asciiz The sum from 0 100 is dn
ThisIs
whatYou
write
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
addiu $29 $29 -32sw $31 20($29)sw $4 32($29)sw $5 36($29)sw $0 24($29)sw $0 28($29)lw $14 28($29)lw $24 24($29)multu $14 $14addiu $8 $14 1slti $1 $8 101sw $8 28($29)mflo $15addu $25 $24 $15bne $1 $0 -9sw $25 24($29)lui $4 4096lw $5 24($29)jal 1048812addiu $4 $4 1072lw $31 20($29)addiu $29 $29 32jr $31move $2 $0
You sometimes read
This in the debugger
Especially when you
Are learning
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
00100111101111011111111111100000
10101111101111110000000000010100
10101111101001000000000000100000
10101111101001010000000000100100
10101111101000000000000000011000
10101111101000000000000000011100
10001111101011100000000000011100
10001111101110000000000000011000
00000001110011100000000000011001
00100101110010000000000000000001
00101001000000010000000001100101
10101111101010000000000000011100
00000000000000000111100000010010
00000011000011111100100000100001
00010100001000001111111111110111
10101111101110010000000000011000
00111100000001000001000000000000
10001111101001010000000000011000
00001100000100000000000011101100
00100100100001000000010000110000
10001111101111110000000000010100
00100111101111010000000000100000
00000011111000000000000000001000
00000000000000000001000000100001
If you can read this
You are a computer
Not for humanconsumption
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form
The object file header describes the size and position of the other pieces ofthe file
The text segment rsaquo contains the machine language code for routines in the source
file These routines may be unexecutable because of unresolved references
The data segment rsaquo contains a binary representation of the data in the source file
The data also may be incomplete because of unresolved references to labels in other files
The relocation information rsaquo identifies instructions and data words that depend on absolute
addresses These references must change if portions of the program are moved in memory
The symbol table rsaquo associates addresses with external labels in the source file and
lists unresolved references The debugging information
rsaquo contains a concise description of the way in which the program was compiled so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form