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
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif



PUBLIC _main
; COMDAT _main
_TEXT SEGMENT
_a$ = -4
_b$ = -8
_c$ = -12
_main PROC NEAR ; COMDAT
; 2 : {
push ebp
mov ebp, esp
sub esp, 76 ; 0000004cH
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-76]
mov ecx, 19 ; 00000013H
mov eax, -858993460 ; ccccccccH
rep stosd
; 3 : int a = 7;
mov DWORD PTR _a$[ebp], 7
; 4 : int b = 15;
mov DWORD PTR _b$[ebp], 15 ; 0000000fH

; 5 : int c;
; 6 : c = b + a;
mov eax, DWORD PTR _b$[ebp]
add eax, DWORD PTR _a$[ebp]
mov DWORD PTR _c$[ebp], eax
; 7 : }

pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
_main ENDP
_TEXT ENDS
END