[CSCI2321] gcc compiler on puck

John Howland jhowland at ariel.cs.trinity.edu
Mon Feb 7 11:29:35 CST 2005


As a follow-on from today's class, I have attached 4 files.  They are:

array.c  (you probably have this in your copy of ~jhowland/cs2321)
array-puck-cc.s  (this file was produced by the current cc compiler and has the reg1 problem and is not usable)
array-puck-gcc.s (this file was produced by the current gcc compiler -- gcc -S array.c)
array-puck-oldcc.s (this file was produced by an older cc compiler the last time I taught this course)

The latter two of these files are instructive to use on xspim.

Remember, you must have the file trap.handler in the directory from which
you envoke xspim.  To get this file,

(cd ~/cs2321/mips-asm-examples ; cp ~jhowland/cs2321/mips-asm-examples/trap.handler ./)

I would encourage you to use the gcc compiler when exploring
mips assembly code examples which are generated from C programs.
It produces good code and has fewer assembler directives (.ops) which
must be commented out.

-- 
_______________________________________________________________
John E. Howland       url: http://www.cs.trinity.edu/~jhowland/
Computer Science    email: jhowland at ariel.cs.trinity.edu
Trinity University  voice: (210) 999-7364
One Trinity Place     fax: (210) 999-7477
San Antonio, Texas  78212-7200
-------------- next part --------------
int main(int argc, char *argv[])
{
  int a[4], sum=0 , i=0;

  init:  a[i] = i;
         i = i + 1;
         if ( i != 4 ) goto init;

  i = 0;

  loop:  sum = sum + a[i];
         i = i + 1;
         if ( i != 4 ) goto loop;
}
-------------- next part --------------
#	.set	noreorder
#	.set	noat
	#  /usr/lib32/cmplrs/be::7.30
	#ism	1275524910

	#-----------------------------------------------------------
	# Compiling array.c (/tmp/ctmB.BAAa00FhC)
	#-----------------------------------------------------------

	#-----------------------------------------------------------
	# Options:
	#-----------------------------------------------------------
	#  Target:R5000, ISA:mips4, Pointer Size:32
	#  -O0	(Optimization level)
	#  -g0	(Debug level)
	#  -m1	(Report warnings)
	#-----------------------------------------------------------

#	.file	1	"/jhowland/cs2321/mips-asm-examples/array.c"

#	.section .text, 1, 0x00000006, 4, 8
#.text:
#	.section .text

	# Program Unit: main
	.ent	main
#	.globl	main
main:	# 0x0
#	.dynsym	main	sto_default
#	.frame	$sp, 48, $31
#	.mask	0x80000000, -24
	# a = 8
	# sum = 0
	# i = 4
	# lcl_spill_temp_0 = 24
#	.loc	1 2 1
.BB1.main:	# 0x0
	addiu $sp,$sp,-48             	#  
	sd $31,24($sp)                	#  lcl_spill_temp_0
	sw $4,36($sp)                 	#  argc
	sw $5,44($sp)                 	#  argv
#	.loc	1 3 13
	sw $0,0($sp)                  	#  sum
#	.loc	1 3 21
	sw $0,4($sp)                  	#  i
init:	# 0x18
#	.loc	1 5 10
	lw $4,4($sp)                  	#  i
	addiu $5,$sp,8                	#  a
	lw $6,4($sp)                  	#  i
	sll $6,$6,2                   	#  
	addu $5,$5,$6                 	#  
	sw $4,0($5)                   	#  
#	.loc	1 6 10
	lw $3,4($sp)                  	#  i
	addiu $3,$3,1                 	#  
	sw $3,4($sp)                  	#  i
#	.loc	1 7 10
	lw $1,4($sp)                  	#  i
	addiu $2,$0,4                 	#  
	bne $1,$2,init                	#  
	nop                           	#  
.BB3.main:	# 0x4c
#	.loc	1 9 3
	sw $0,4($sp)                  	#  i
loop:	# 0x50
#	.loc	1 11 10
	addiu $10,$sp,8               	#  a
	lw $11,4($sp)                 	#  i
	sll $11,$11,2                 	#  
	addu $10,$10,$11              	#  
	lw $10,0($10)                 	#  
	lw $11,0($sp)                 	#  sum
	addu $10,$10,$11              	#  
	sw $10,0($sp)                 	#  sum
#	.loc	1 12 10
	lw $9,4($sp)                  	#  i
	addiu $9,$9,1                 	#  
	sw $9,4($sp)                  	#  i
#	.loc	1 13 10
	lw $7,4($sp)                  	#  i
	addiu $8,$0,4                 	#  
	bne $7,$8,loop                	#  
	nop                           	#  
.BB5.main:	# 0x8c
#	.loc	1 14 1
	or $2,$0,$0                   	#  
	ld $31,24($sp)                	#  lcl_spill_temp_0
	addiu $sp,$sp,48              	#  
	jr $31                        	#  
	nop                           	#  
	.end	main
#	.section .text
#	.align 3
#	.gpvalue 30720
-------------- next part --------------
#	.file	1 "array.c"
#	.option pic2
gcc2_compiled.:
__gnu_compiled_c:
#	.text
#	.align	2
#	.globl	main
	.ent	main
main:
#	.frame	$fp,40,$31		# vars= 24, regs= 2/0, args= 0, extra= 8
#	.mask	0x50000000,-4
#	.fmask	0x00000000,0
#	.set	noreorder
#	.cpload	$25
#	.set	reorder
	subu	$sp,$sp,40
#	.cprestore 0
	sw	$fp,36($sp)
	sw	$28,32($sp)
	move	$fp,$sp
	sw	$4,40($fp)
	sw	$5,44($fp)
	sw	$0,24($fp)
	sw	$0,28($fp)
$L2:
	lw	$2,28($fp)
	move	$3,$2
	sll	$2,$3,2
	addu	$3,$fp,8
	addu	$2,$3,$2
	lw	$3,28($fp)
	sw	$3,0($2)
	lw	$2,28($fp)
	addu	$3,$2,1
	sw	$3,28($fp)
	lw	$2,28($fp)
	li	$3,4			# 0x4
	beq	$2,$3,$L3
	j	$L2
$L3:
	sw	$0,28($fp)
$L4:
	lw	$2,28($fp)
	move	$3,$2
	sll	$2,$3,2
	addu	$3,$fp,8
	addu	$2,$3,$2
	lw	$3,24($fp)
	lw	$2,0($2)
	addu	$3,$3,$2
	sw	$3,24($fp)
	lw	$2,28($fp)
	addu	$3,$2,1
	sw	$3,28($fp)
	lw	$2,28($fp)
	li	$3,4			# 0x4
	beq	$2,$3,$L5
	j	$L4
$L5:
$L1:
	move	$sp,$fp
	lw	$fp,36($sp)
	addu	$sp,$sp,40
	j	$31
	.end	main
-------------- next part --------------
#	.verstamp	3 19
#	.option	pic2
#	.text	
#	.align	2
#	.file	2 "array.c"
#	.globl	main
#	.loc	2 2
 #   1	int main(int argc, char *argv[])
 #   2	{
	.ent	main 2
main:
#	.option	O1
#	.set	 noreorder
#	.cpload	$25
#	.set	 reorder
	subu	$sp, 24
	sw	$4, 24($sp)
	sw	$5, 28($sp)
#	.frame	$sp, 24, $31
#	.loc	2 2
#	.loc	2 3
 #   3	  int a[4], sum=0 , i=0;
	sw	$0, 4($sp)
#	.loc	2 3
	sw	$0, 0($sp)
#	.loc	2 5
 #   4	
 #   5	  init:  a[i] = i;
$32:
#	.loc	2 5
	lw	$14, 0($sp)
	mul	$15, $14, 4
	addu	$24, $sp, 8
	addu	$25, $15, $24
	sw	$14, 0($25)
#	.loc	2 6
 #   6	         i = i + 1;
	lw	$8, 0($sp)
	addu	$9, $8, 1
	sw	$9, 0($sp)
#	.loc	2 7
 #   7	         if ( i != 4 ) goto init;
	bne	$9, 4, $32
#	.loc	2 7
#	.loc	2 9
 #   8	
 #   9	  i = 0;
	sw	$0, 0($sp)
#	.loc	2 11
 #  10	
 #  11	  loop:  sum = sum + a[i];
$33:
#	.loc	2 11
	lw	$10, 0($sp)
	mul	$11, $10, 4
	addu	$12, $sp, 8
	addu	$13, $11, $12
	lw	$15, 0($13)
	lw	$24, 4($sp)
	addu	$14, $15, $24
	sw	$14, 4($sp)
#	.loc	2 12
 #  12	         i = i + 1;
	addu	$25, $10, 1
	sw	$25, 0($sp)
#	.loc	2 13
 #  13	         if ( i != 4 ) goto loop;
	bne	$25, 4, $33
#	.loc	2 13
#	.loc	2 14
 #  14	}
	move	$2, $0
#	.livereg	0x2000FF0E,0x00000FFF
	addu	$sp, 24
	j	$31
	.end	main


More information about the CSCI2321 mailing list