## Output generated by ./comp @ ubuntu8041 ## Wed Nov 19 17:50:55 2008 ## Compiler Construction Course - Leiden University - LIACS ## Johan IJsveld - Rick van der Zwet ## BSD Licenced .data # Global data section .align 4 __x: .word 0 __y: .word 0 .text # Code section .align 4 .globl main .ent main main: addi $sp, $sp, -4 jal __example # Jump to program body addi $v0, $0, 10 # Exit system call syscall .end main .ent __example __example: sw $ra, 0($sp) # Set up stack frame sw $fp, -4($sp) move $fp, $sp addi $sp, $sp, -12 jal __readinteger lw $t0, 0($fp) # Load integer Register move $t0, $v0 lw $t1, __x # Load integer Register move $t1, $t0 sw $t0, 0($fp) # Write back integer register sw $t1, __x # Write back integer register jal __readinteger lw $t0, 0($fp) # Load integer Register move $t0, $v0 lw $t1, __y # Load integer Register move $t1, $t0 move $v1, $t1 sw $v1, 0($sp) addi $sp, $sp, -4 lw $t2, __x # Load integer Register move $v1, $t2 sw $v1, 0($sp) addi $sp, $sp, -4 sw $t0, 0($fp) # Write back integer register sw $t1, __y # Write back integer register sw $t2, __x # Write back integer register jal __gcd lw $t0, 0($fp) # Load integer Register move $t0, $v0 move $v1, $t0 sw $v1, 0($sp) addi $sp, $sp, -4 sw $t0, 0($fp) # Write back integer register jal __writeinteger lw $ra, 0($fp) # Return from call lw $fp, -4($fp) addi $sp, $sp, 12 jr $ra .end __example .ent __gcd __gcd: sw $ra, 0($sp) # Set up stack frame sw $fp, -4($sp) move $fp, $sp addi $sp, $sp, -36 lw $t0, -4($fp) # Load integer Register addi $a0, $0, 0 bne $a0, $t0, _L1 # Branch Instruction Int lw $t1, -8($fp) # Load integer Register lw $t2, 0($fp) # Load integer Register move $t1, $t2 j _L0 _L1: lw $t3, -16($fp) # Load integer Register mul $t3, $t2, $t0 # Binary Arithmetic move $v1, $t3 sw $v1, 0($sp) addi $sp, $sp, -4 move $v1, $t0 sw $v1, 0($sp) addi $sp, $sp, -4 sw $t0, -4($fp) # Write back integer register sw $t1, -8($fp) # Write back integer register sw $t2, 0($fp) # Write back integer register sw $t3, -16($fp) # Write back integer register jal __gcd lw $t0, -20($fp) # Load integer Register move $t0, $v0 lw $t1, -8($fp) # Load integer Register move $t1, $t0 _L0: sw $t0, -20($fp) # Write back integer register sw $t1, -8($fp) # Write back integer register lw $t0, -8($fp) # Load integer Register move $v0, $t0 # Store integer return value lw $ra, 0($fp) # Return from call lw $fp, -4($fp) addi $sp, $sp, 44 jr $ra .end __gcd .ent __readinteger # Start of builtin functions and procedures __readinteger: addi $v0, $0, 5 syscall addi $sp, $sp, 4 jr $ra .end __readinteger .ent __writeinteger __writeinteger: lw $a0, 4($sp) addi $v0, $0, 1 syscall addi $sp, $sp, 4 jr $ra .end __writeinteger