Title: Register Windows
1(No Transcript)
2Register Windows
- save and restore
- Window over/under flow
3Global Variables
- Use data definition pseudo-ops
.data ! Start of data
segment x .word 12 ! int x 12 y .byte
'a' ! char y 'a' .align 2 ! Get alignment
correct z .half 0xffff ! short z
0xffff .align 4 ! Get alignment
correct lst .skip 4 100 ! int
lst100 .text ! Start of program
segment . . .
4Addressing Global Data
x .word 3 . . . mov x, l0 ld
l0, o1
5How do we handle addresses?
- Use sethi to set high 22 bits
- Use or to set low 10 bits
x .word 3 . . . sethi x gtgt 10, l0
or l0, x 0x3ff, l0 ld l0,
o1
6Alternatives
x .word 3 . . . sethi hi(x), l0
or l0, lo(x), l0 ld l0, o1
76. Subroutines and Parameters
call label
8Return
ret
9Skeleton for Subroutines
call SUBR nop ! Delay
slot ... SUBR save sp, ..., sp
... ret restore ! Delay slot
10Parameter Passing
- Registers
- o6 Stack Pointer/Frame Pointer
- o7 Return Address
- o0...o5 Available for six parameters
11Stack Space
- Space on the stack must be reserved for
- Window overflow (64 bytes)
- A structure pointer (4 bytes)
- Register parameters (24 bytes)
- Local variables (? bytes)
12More Than Six Parameters?
13Return Values
- i0 for word values
- Pointer to structure on stack for larger
structures
14Leaf Subroutines
- No save or restore
- Use only out registers
- Return
retl
15Separate Assembly Compilation
- C and Assembly Language
- Must have a .global directive
16Example C Code
/ Demonstrate linking C with assembly. George
Wells - 15 July 1992. Original program by R.
Paul. / void summer (int acc, char
ptr) main (int argc, char argv ) int
sum 0 while (--argc) summer(sum,
argv) printf("sum is d\n", sum) /
main /
17Example Assembler
include(macro_defs.m) ! Define symbolic constants
for parameters. define(acc, i0) !
Pointer to sum define(ptr, i1) !
Pointer to string begin_fn(summer)! void
summer(intacc, charptr) call atoi
! get atoi(ptr) mov ptr, o0 !
parameter to atoi ld acc,
o1 add o0, o1, o0 ! acc
atoi(ptr) st o0, acc end_fn
! summer
18Makefile
sum1 sum1.o summer.o gcc -g sum1.o
summer.o -o sum1 sum1.o sum1.c gcc -g
-c sum1.c summer.o summer.s gcc -g -c
summer.s -o summer.o summer.s summer.m
rm -f summer.s m4 summer.m gt summer.s
19Calling C Routines
fmt .asciz "The answer is d\n" . . .
set fmt, o0 ! fmt - 1st parameter call
printf ! printf("The ...", ans) mov
l3, o1 ! ans as 2nd parameter
20(No Transcript)