I want to print star pattern in this way:
****** ***** **** *** ** *
but it is printing this way:
****** ****** ****** ****** ****** ******
Can someone help me? This is my code:
main:
daddiu $sp,$sp,-48
sd $31,40($sp)
sd $fp,32($sp)
sd $28,24($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(main)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(main)))
sw $0,0($fp)
b .L2
nop
.L5:
li $2,6 # 0x6
sw $2,4($fp)
b .L3
nop
.L4:
li $4,42 # 0x2a
ld $2,%call16(putchar)($28)
move $25,$2
nop
lw $2,4($fp)
addiu $2,$2,-1
sw $2,4($fp)
.L3:
lw $2,4($fp)
bgez $2,.L4
nop
li $4,10 # 0xa
ld $2,%call16(putchar)($28)
move $25,$2
nop
lw $2,0($fp)
addiu $2,$2,1
sw $2,0($fp)
.L2:
lw $2,0($fp)
slt $2,$2,6
bne $2,$0,.L5
nop
nop
move $sp,$fp
ld $31,40($sp)
ld $fp,32($sp)
ld $28,24($sp)
daddiu $sp,$sp,48
j $31
nop
Hey may be you are doing mistake in setting up loop in mips
You are not properly initializing the inner loop
if you are converting c program into mips than correctly set the limitation of inner loop
main:
daddiu $sp,$sp,-48
sd $31,40($sp)
sd $fp,32($sp)
sd $28,24($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(main)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(main)))
sw $0,0($fp)
b .L2
nop
.L5:
li $2,5 # 0x5
sw $2,4($fp)
b .L3
nop
.L4:
li $4,42 # 0x2a
ld $2,%call16(putchar)($28)
move $25,$2
nop
lw $2,4($fp)
addiu $2,$2,-1
sw $2,4($fp)
.L3:
lw $3,4($fp)
lw $2,0($fp)
slt $2,$3,$2
beq $2,$0,.L4
nop
li $4,10 # 0xa
ld $2,%call16(putchar)($28)
move $25,$2
nop
lw $2,0($fp)
addiu $2,$2,1
sw $2,0($fp)
.L2:
lw $2,0($fp)
slt $2,$2,6
bne $2,$0,.L5
nop
nop
move $sp,$fp
ld $31,40($sp)
ld $fp,32($sp)
ld $28,24($sp)
daddiu $sp,$sp,48
j $31
nop
#include <iostream>
using namespace std;
int main(){
int a, b;
for(b=1;b<=6;b++){
for(a=1;a<=6;a++){
if(a<=7-b)
cout<<"*";
else
cout<<" ";
}
cout<<"\n";
}
return 0;
}
#include <iostream>
using namespace std;
int main(){
int i, a;
for(i=1;i<=6;i++){
for(a=1;a<=6;a++){
if(a<=7-i)
cout<<"*";
else
cout<<" ";
}
cout<<"\n";
}
return 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.