General SPARC Information

Registers (general purpose, integer registers):

Common Instructions:

Useful SPARC Floating-Point Information

Floating-point registers:

Floating-point I/O:

Inserting FP constants into your assembly:

Promoting an integer to a single-precision floating-point:

Single-precision operations:

Special purpose operations:

Floating-point memory:

Floating-point Branching:

Example SPARC Floating-Point Program

	.section	".data"
	.align 		4
NL:	.asciz		"\n"
y:	.asciz		"YES\n"
n: 	.asciz		"NO\n"
	.align		4
fpc: 	.single		0r420.25, 0r-23.75	! Two compile-time constants
	.section	".text"
	.align		4
	.global		foo 			! foo ( FLOAT )
foo:
	save		%sp, -(92 + 4) & -8, %sp
	st 		%i0, [%fp-4]
   	ld 		[%fp-4], %f0 		! Put FLOAT param into fp reg
	! Alternatively, you could pass FLOATs directly in the fp regs

	call 		printFloat
	nop
	ret
   	restore

	.section 	".text"
	.align 		4
   	.global 	main
main:
	save 		%sp, -(92 + 4) & -8, %sp
 	set 		fpc, %l0
   	ld 		[%l0], %f0
   	fadds 		%f0, %f0, %f0
! 	.section 	".data" 		! Same as below, but with floating const
! 	.align 		4 			! Shows you can insert constants were needed
!tmp1: 	.single 	0r3
!	.section 	".text"
!	.align 		4
!	set 		tmp1, %l0
!	ld 		[%l0], %f1
	mov 		3, %l0 			! Using integer
	st 		%l0, [%fp-4]
	ld 		[%fp-4], %f1
	fitos 		%f1, %f1 		! Convert bit pattern from int to float
	fdivs 		%f0, %f1, %f0
	fsqrts 		%f0, %f0
   
	call 		printFloat 		! Result already in %f0
	nop
   
	set 		NL, %o0
	call 		printf
	nop
   
	set 		fpc, %l0
	ld 		[%l0+4], %f1 		! get 2nd constant (hence +4)
   
	call 		inputFloat
	nop 					! Result in %f0
   
	fcmps 		%f0, %f1 		! Compare input w/ 2nd const
	nop 					! Needed in between FP compare and FP branch!!!
	fbg 		L1
	nop
  
	set 		y, %o0
	call 		printf
	nop
   
	ba		skip
	nop
   
L1:
	set 		n, %o0
	call 		printf
	nop
skip: 
	call 		inputFloat 
	nop 					! Result in %f0
   
	st		%f0, [%fp-4]
	ld 		[%fp-4], %o0 		! Send using sliding int reg
	! Alternatively can send directly with non-sliding fp reg

	call 		foo
	nop
   
	ret
	restore