NOTE: Use the Stack-based Linkage Conventionfor these programs. In the Settings
ID: 3618116 • Letter: N
Question
NOTE: Use the Stack-based Linkage Conventionfor these programs.
In the Settings menu of SPIM set Bare MachineOFF, Allow Pseudo InstructionsON, Load Trap File ON, DelayedBranches ON, Delayed Loads ON, Mapped IO ON, QuietOFF.
Run the programs by clicking SimulatorGo and thenOK in the pop-up panel.
Write a program that asks if the user wants a triangle or asquare. It then prompts for the size of the object (the number oflines it takes to draw the object). The program then writes atriangle or a square of stars ("*") to the monitor.
or
Write a subroutine for each figure. In them, use a subroutinestarline that writes a line of a given number ofstars.
Printout of program (fromNotepad), screen printout from SPIM showing final values inregisters, screen printout of I/O screen showing result.
Explanation / Answer
x.Xlor="red">please rate -thanks best I can do ## Ch27Pr03.asm ## This program that asks if the user wants a triangle or a square. ## It then prompts for the size of the object. ## It then writes a triangle or a square of stars ("*") to the monitor. .text .globl main main: sub $sp,$sp,4 # push the return address sw $ra,($sp) li $s0,1 # $s0 is 'r' li $s1,2 # $s1 is 't' la $a0,prompt1 # prompt the user li $v0,4 # service 4 syscall li $v0,5 #read char into $v0 syscall #service 5 move $s2,$v0 la $a0,prompt2 # prompt the user li $v0,4 # service 4 syscall li $v0,5 #read int into $v0 syscall #service 5 move $s3,$v0 la $a0,output li $v0,4 syscall move $a0,$s2 move $a1,$s3 beq $a0,$s0,rect beq $a0,$s1,tri j exit tri: jal triangle j exit rect: jal rectangle exit: lw $ra,($sp) # pop return address add $sp,$sp,4 jr $ra # return to OS rectangle: sub $sp,$sp,4 # push the return address sw $ra,($sp) li $t0,0 move $t1,$a1 outer1: li $t2,6 inner1: la $a0,line2 li $v0,4 syscall addi $t2,-1 bnez $t2,inner1 nop la $a0,line3 li $v0,4 syscall addi $t0,1 bne $t0,$t1,outer1 lw $ra,($sp) # pop return address add $sp,$sp,4 jr $ra # return to OS triangle: sub $sp,$sp,4 # push the return address sw $ra,($sp) li $t0,0 move $t1,$a1 outer: li $t2,0 inner: la $a0,line2 &nb
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.