In: Computer Science
1. MIPS assembly language for the first code
.file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .rdata .align 2 $LC0: .ascii "sum=%d\000" .text .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $fp,40,$31 # vars= 8, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-40 sw $31,36($sp) sw $fp,32($sp) move $fp,$sp .cprestore 16 movz $31,$31,$0 sw $0,24($fp) sw $0,28($fp) b $L2 nop $L3: lw $3,24($fp) lw $2,28($fp) nop addu $2,$3,$2 sw $2,24($fp) lw $2,28($fp) nop addiu $2,$2,1 sw $2,28($fp) $L2: lw $2,28($fp) nop slt $2,$2,1000 bne $2,$0,$L3 nop lw $5,24($fp) lw $2,%got($LC0)($28) nop addiu $4,$2,%lo($LC0) lw $2,%call16(printf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,printf 1: jalr $25 nop lw $28,16($fp) move $2,$0 move $sp,$fp lw $31,36($sp) lw $fp,32($sp) addiu $sp,$sp,40 j $31 nop .set macro .set reorder .end main .size main, .-main .ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609"
2. MIPS assembly language for the second code
.file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .rdata .align 2 $LC0: .ascii "%d\000" .align 2 $LC1: .ascii "%d=>%d\000" .text .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $fp,88,$31 # vars= 56, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-88 sw $31,84($sp) sw $fp,80($sp) move $fp,$sp .cprestore 16 movz $31,$31,$0 sw $0,24($fp) b $L2 nop $L3: addiu $3,$fp,36 lw $2,24($fp) nop sll $2,$2,2 addu $2,$3,$2 move $5,$2 lw $2,%got($LC0)($28) nop addiu $4,$2,%lo($LC0) lw $2,%call16(__isoc99_scanf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,__isoc99_scanf 1: jalr $25 nop lw $28,16($fp) lw $2,24($fp) nop addiu $2,$2,1 sw $2,24($fp) $L2: lw $2,24($fp) nop slt $2,$2,10 bne $2,$0,$L3 nop lw $2,36($fp) nop sw $2,28($fp) li $2,1 # 0x1 sw $2,24($fp) b $L4 nop $L6: lw $2,24($fp) nop sll $2,$2,2 addiu $3,$fp,24 addu $2,$3,$2 lw $3,12($2) lw $2,28($fp) nop slt $2,$3,$2 beq $2,$0,$L5 nop lw $2,24($fp) nop sll $2,$2,2 addiu $3,$fp,24 addu $2,$3,$2 lw $2,12($2) nop sw $2,28($fp) lw $2,24($fp) nop sw $2,32($fp) $L5: lw $2,24($fp) nop addiu $2,$2,1 sw $2,24($fp) $L4: lw $2,24($fp) nop slt $2,$2,10 bne $2,$0,$L6 nop lw $6,28($fp) lw $5,32($fp) lw $2,%got($LC1)($28) nop addiu $4,$2,%lo($LC1) lw $2,%call16(printf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,printf 1: jalr $25 nop lw $28,16($fp) move $2,$0 move $sp,$fp lw $31,84($sp) lw $fp,80($sp) addiu $sp,$sp,88 j $31 nop .set macro .set reorder .end main .size main, .-main .ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609"