Simple C code as compiled by different compilers

main()
{
int a = 7;
int b = 15;
int c;
c = b + a;
}





















SPIM assembly

##################################################################
# addasm.s
# addition of two integers
#that are automatic variables.
# the result is stored on stack.
#
#################################################################.verstamp 3 19
.text
.align 2
.globl main
# 1 main()
# 2 {
main:
# 3 int a = 7;
li $14, 7
sw $14, 12($sp)
# 4 int b = 15;
li $15, 15
sw $15, 8($sp)
# 5 int c;
# 6 c = b + a;
li $24, 22 # the compiler is smart:
# performs addtion of two constants
# at compile time!
sw $24, 4($sp)
# 7 }
.end main


MIPS assembly






























Pentium Assembly

TITLE F:\Cs342fall99\Sep27\testadd\addasm.c
.386P
include listing.inc
if @Version gt 510
.model FLAT
else
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS
CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
_BSS ENDS
$$SYMBOLS SEGMENT BYTE USE32 'DEBSYM'
$$SYMBOLS ENDS
$$TYPES SEGMENT BYTE USE32 'DEBTYP'
$$TYPES ENDS
_TLS SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS ENDS
; COMDAT _main