Академический Документы
Профессиональный Документы
Культура Документы
14.1
14.2
Text segment
Data segment
Relocation information
Symbol table
Debugging information
14.3
Relocation records
C library print:
14.4
Source file
Assembler
Object file
Linker
Executable file
Source file
Assembler
Object file
Program library
14.5
xspim
PC = 00000000 Status = 00000000 R0 R1 R2 R3 R4 R5 R6 R7 FP0 FP2 FP4 FP6 (r0) (at) (v0) (v1) (a0) (a1) (a2) (a3) = = = = = = = = = = = = 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0.000000 0.000000 0.000000 0.000000 EPC HI R8 R9 R10 R11 R12 R13 R14 R15 FP8 FP10 FP12 FP14 = 00000000 = 00000000 (t0) (t1) (t2) (t3) (t4) (t5) (t6) (t7) = = = = = = = = = = = = Cause LO = 00000000 BadVaddr = 00000000 R16 R17 R18 R19 R20 R21 R22 R23 FP16 FP18 FP20 FP22 (s0) (s1) (s2) (s3) (s4) (s5) (s6) (s7) = = = = = = = = = = = = 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0.000000 0.000000 0.000000 0.000000 = 00000000
General registers
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0.000000 0.000000 0.000000 0.000000 R24 R25 R26 R27 R28 R29 R30 R31 FP24 FP26 FP28 FP30 (t8) (s9) (k0) (k1) (gp) (sp) (s8) (ra) = = = = = = = = = = = = 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0.000000 0.000000 0.000000 0.000000
Register display
Single floating-point registers Control buttons quit print load breakpt run help step terminal Text segments
[0x00400000] [0x00400004] [0x00400008] [0x0040000c] [0x00400010] [0x00400014] [0x00400018] [0x0040001c] 0x8fa40000 0x27a50004 0x24a60004 0x00041080 0x00c23021 0x0c000000 0x3402000a 0x0000000c lw $4, 0($29) addiu $5, $29, 4 addiu $6, $5, 4 sll $2, $4, 2 addu $6, $6, $2 jal 0x00000000 [main] ori $2, $0, 10 syscall ; ; ; ; ; ; ; ; 89: 90: 91: 92: 93: 94: 95: 96: lw $a0, 0($sp) addiu $al, $sp, 4 addiu $a2, $al, 4 sll $v0, $a0, 2 addu $a2, $a2, $v0 jal main li $v0 10 syscall
clear mode
set value
Text segments
Data segments
[0x10000000] ... [0x10010000] [0x10010004] 0x74706563 [0x10010010] 0x72727563 [0x10010020] 0x000a6465 [0x10010030] 0x0000205d [0x10010040] 0x61206465 [0x10010050] 0x642f7473 [0x10010060] 0x555b2020 [0x10010070] 0x73736572 0x00000000 0x206e6f69 0x61206465 0x495b2020 0x20200000 0x65726464 0x20617461 0x696c616e 0x206e6920 0x636f2000 0x6920646e 0x7265746e 0x616e555b 0x69207373 0x63746566 0x64656e67 0x726f7473
SPIM messages
SPIM Version 5.9 of January 17, 1997 Copyright (c) 19901997 by James R. Larus (larus@cs.wisc.edu) All Rights Reserved. See the file README for a full copyright notice.
14.7
Reserved
14.8
These registers allow the programmer to refer to memory locations with base+offset addressing.
Code segment pointer Stack segment pointer (top of stack) Data segment pointer 0 Data segment pointer 1 Data segment pointer 2 Data segment pointer 3 Instruction pointer (PC) Condition codes
14.9
Assembler Directives
Data alignment: .align n (n is a power of 2) - by default, auto alignment is on for word, half-word, float and double Data segment definition: .data <addr>
.data MY_VAR1: .float 3.1416936 GREET: .asciiz: Welcome to my first MIPS program DUDE: .word 0xdada B_ARRAY: .byte 32, 12, 23, 3, 35, 76, 99
10
Assembler Directives
Comments:
# this is a comment
Address labels:
addi $t0, $zero, 64 sub $t1, $zero, 1 START: sub bne $t0, $t0, $t1 $t0, $zero, START
14.11
11
Assembler Directives
Space allocation: (in the data segment)
MY_EMPTY_ARRAY: .space n
14.12
12
Services
If you write code for a bare machine, your program must be a self-contained unit. All the functionality you require must be provided by your own code. If you write code to run on a machine with an operating system, you can make use of the (possibly many) services offered. First, you must figure out how to invoke these services, what parameters need to passed and how you pass these parameters. XSPIM doesnt fall in either of these cases, but it offers you a few services that can make your life easier.
14.13
13
XSPIM Services
Service
print_int print_float print_double print_string read_int read_float read_double read_string sbrk exit
Code
1 2 3 4 5 6 7 8 9 10
Arguments
$a0 = integer $f12 = float $f12 = double $a0 = string
Result
integer (in $v0) float (in $f0) double (in $f0) $a0 = buffer, $a1 = length $a0 = amount address (in $v0)
14.14
14
XSPIM Startup
lw addiu addiu sll addu jal li syscall $a0, $a1, $a2, $v0, $a2, main $v0, 0($sp) #argc $sp, 4 #argv $a1, 4 #envp $a0, 2 $a2, $v0 10 # syscall 10 (exit)
Your program should better define a main symbol because XSPIM will look for it.
14.15
15
Recursive Procedures
main( ) { printf(10! = %d\n, fact(10); } int fact(int n) { if (n<1) return (1); else return (n*fact(n-1)); }
14.16
16
fact (10)
fact (9)
fact (7)
17
.text
fact:
$sp, $sp, 32 $ra, 24($sp) $fp, 16($sp) $fp, $sp, 28 $a0, 10 fact $ra, 24($sp) $fp, 16($sp) $sp, $sp, 32 $ra
$L2:
$L1:
10! =
$sp, $sp, 32 $ra, 24($sp) $fp, 16($sp) $fp, $sp, 28 $a0, 0($fp) $v0, 0($fp) $v0, $L2 $v0, 1 $L1 $v1, 0($fp) $v0, $v1, 1 $a0, $v0 fact $v1, 0($fp) $v0, $v0, $v1 $ra, 24($sp) $fp, 16($sp) $sp, $sp, 32 $ra
14.18
18