Register Windows - PowerPoint PPT Presentation

About This Presentation
Title:

Register Windows

Description:

Use data definition pseudo-ops .data ! Start of data segment. x: .word 12 ! int x = 12; ... Use only 'out' registers. Return: retl. jmpl %o7 8, %g0. Separate ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 21
Provided by: george354
Category:

less

Transcript and Presenter's Notes

Title: Register Windows


1
(No Transcript)
2
Register Windows
  • save and restore
  • Window over/under flow

3
Global 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 . . .
4
Addressing Global Data
x .word 3 . . . mov x, l0 ld
l0, o1
5
How 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
6
Alternatives
x .word 3 . . . sethi hi(x), l0
or l0, lo(x), l0 ld l0, o1
7
6. Subroutines and Parameters
  • Simple Call

call label
8
Return
ret
9
Skeleton for Subroutines
call SUBR nop ! Delay
slot ... SUBR save sp, ..., sp
... ret restore ! Delay slot
10
Parameter Passing
  • Registers
  • o6 Stack Pointer/Frame Pointer
  • o7 Return Address
  • o0...o5 Available for six parameters

11
Stack 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)

12
More Than Six Parameters?
  • Use the stack

13
Return Values
  • i0 for word values
  • Pointer to structure on stack for larger
    structures

14
Leaf Subroutines
  • No save or restore
  • Use only out registers
  • Return

retl
15
Separate Assembly Compilation
  • C and Assembly Language
  • Must have a .global directive  

16
Example 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 /
17
Example 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
18
Makefile
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
19
Calling C Routines
  • Very simple

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)
Write a Comment
User Comments (0)
About PowerShow.com