#include <stdio.h>
int sum (int L, int U) {
if (L == U) return L;
else {
int lower, upper;
int mid = (U+L)/2;
lower = sum (L, mid);
upper = sum(mid+1, U);
return (lower+upper);
}
}
int main(){
int x,y;
scanf("%d %d",&x,&y);
printf("The result is: %d\n",sum(x,y));
}
答案 0 :(得分:2)
我会屈服于讽刺的诱惑并发布这个:
.file 1 "hello.c"
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.text
.align 2
.globl sum
.set nomips16
.ent sum
.type sum, @function
sum:
.frame $sp,40,$31 # vars= 16, regs= 1/0, args= 16, gp= 0
.mask 0x80000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-40
sw $31,36($sp)
sw $4,40($sp)
sw $5,44($sp)
lw $3,40($sp)
lw $2,44($sp)
nop
bne $3,$2,$L2
nop
lw $2,40($sp)
j $L3
nop
$L2:
lw $3,44($sp)
lw $2,40($sp)
nop
addu $2,$3,$2
srl $3,$2,31
addu $2,$3,$2
sra $2,$2,1
sw $2,16($sp)
lw $4,40($sp)
lw $5,16($sp)
jal sum
nop
sw $2,20($sp)
lw $2,16($sp)
nop
addiu $2,$2,1
move $4,$2
lw $5,44($sp)
jal sum
nop
sw $2,24($sp)
lw $3,20($sp)
lw $2,24($sp)
nop
addu $2,$3,$2
$L3:
lw $31,36($sp)
addiu $sp,$sp,40
j $31
nop
.set macro
.set reorder
.end sum
.size sum, .-sum
.rdata
.align 2
$LC0:
.ascii "%d %d\000"
.align 2
$LC1:
.ascii "The result is: %d\012\000"
.text
.align 2
.globl main
.set nomips16
.ent main
.type main, @function
main:
.frame $sp,32,$31 # vars= 8, regs= 2/0, args= 16, gp= 0
.mask 0x80010000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-32
sw $31,28($sp)
sw $16,24($sp)
lui $2,%hi($LC0)
addiu $3,$2,%lo($LC0)
addiu $2,$sp,20
move $4,$3
addiu $3,$sp,16
move $5,$3
move $6,$2
jal scanf
nop
lui $2,%hi($LC1)
addiu $16,$2,%lo($LC1)
lw $3,16($sp)
lw $2,20($sp)
move $4,$3
move $5,$2
jal sum
nop
move $4,$16
move $5,$2
jal printf
nop
lw $31,28($sp)
lw $16,24($sp)
addiu $sp,$sp,32
j $31
nop
.set macro
.set reorder
.end main
.size main, .-main
.ident "GCC: (GNU) 4.5.2"
这是由我刚刚为mips-linux-elf目标构建的GCC交叉编译器生成的,使用以下命令行:
mips-linux-elf-gcc -fomit-frame-pointer -S hello.c
由于您使用的是Windows,因此您应该在Google上搜索mips cross-compiler for windows
。
你到底想做什么?