Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MIPS Assembly code for arithmetics. Do it in PCSPIM only for MIPS! Objectives: w

ID: 2247720 • Letter: M

Question

MIPS Assembly code for arithmetics. Do it in PCSPIM only for MIPS!

Objectives: write assembly language programs to -perform arithmetic and logical operations on variables -use syscall operations to display integers and strings on the console window -use syscall operations to read integers from the keyboard. Assignment Description: The read int system call (number 5) will cause the running program to stop and wait for the user to type in an integer at the keyboard. The integer will be put into $v0 register and will be available after the syscall completes. Write a MIPS assembly language program which prompts for a user to enter four integers and calls read int four times to read in four integers. The program should perform addition, subtraction, multiplication, integer division, and modulo operation (compute the remainder of their division) using two of these four integers (see the C program below), then display their result on the console window. Also compute num2 (num4 + numl mod 3) *2) /num3) where numl is the first read integer, num2 is the second read integer, num3 is the third read integer, and num4 is the forth read integer, and display the result. Name your source code file assignment3.S. The following shows how it looks like in a C progranm int num1, num2, num3, num4, ansl, ans2, ans3, ans4, ans5, ans6 printf C"Enter a value: "); //read an integer from a user input and store it in numl scanf ("%d", &num1;) ; printf ("Enter another value: "); //read an integer from a user input and store it in num2 scanf ("%d", &num2;); printf ("Enter one more value: ") //read an integer from a user input and store it in num3 scanf ("sd", &num3;) printf ("Enter one more value: ") //read an integer from a user input and store it in num4 scanf ("sd", &num4;) ans! = num2 +num3 ; //addition printf( "num2+num3-%d ", ans!) ; ans2 = num3-num4; //subtract 1 n printf( "num3-num4-%d ", ans2);

Explanation / Answer

.file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .rdata .align 2 $LC0: .ascii "Enter a value: " .align 2 $LC1: .ascii "%d" .align 2 $LC2: .ascii "Enter another value: " .align 2 $LC3: .ascii "Enter one more value: " .align 2 $LC4: .ascii "num2+num3=%d
" .align 2 $LC5: .ascii "num3-num4==%d
" .align 2 $LC6: .ascii "num3*num1=%d
" .align 2 $LC7: .ascii "num2/num4=%d
" .align 2 $LC8: .ascii "num4 mod num3=%d
" .align 2 $LC9: .ascii "num2-(((num4+num1%3)*2)/num3)=%d
" .text .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $fp,72,$31 # vars= 40, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-72 sw $31,68($sp) sw $fp,64($sp) move $fp,$sp .cprestore 16 movz $31,$31,$0 lw $2,%got($LC0)($28) nop addiu $4,$2,%lo($LC0) lw $2,%call16(puts)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,puts 1: jalr $25 nop lw $28,16($fp) addiu $2,$fp,48 move $5,$2 lw $2,%got($LC1)($28) nop addiu $4,$2,%lo($LC1) 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) nop lw $2,%got($LC2)($28) nop addiu $4,$2,%lo($LC2) lw $2,%call16(puts)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,puts 1: jalr $25 nop lw $28,16($fp) addiu $2,$fp,52 move $5,$2 lw $2,%got($LC1)($28) nop addiu $4,$2,%lo($LC1) 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) nop lw $2,%got($LC3)($28) nop addiu $4,$2,%lo($LC3) lw $2,%call16(puts)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,puts 1: jalr $25 nop lw $28,16($fp) addiu $2,$fp,56 move $5,$2 lw $2,%got($LC1)($28) nop addiu $4,$2,%lo($LC1) 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) nop lw $2,%got($LC3)($28) nop addiu $4,$2,%lo($LC3) lw $2,%call16(puts)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,puts 1: jalr $25 nop lw $28,16($fp) addiu $2,$fp,60 move $5,$2 lw $2,%got($LC1)($28) nop addiu $4,$2,%lo($LC1) 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 $3,52($fp) lw $2,56($fp) nop addu $2,$3,$2 sw $2,24($fp) lw $5,24($fp) lw $2,%got($LC4)($28) nop addiu $4,$2,%lo($LC4) lw $2,%call16(printf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,printf 1: jalr $25 nop lw $28,16($fp) lw $3,56($fp) lw $2,60($fp) nop subu $2,$3,$2 sw $2,28($fp) lw $5,28($fp) lw $2,%got($LC5)($28) nop addiu $4,$2,%lo($LC5) lw $2,%call16(printf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,printf 1: jalr $25 nop lw $28,16($fp) lw $3,56($fp) lw $2,48($fp) nop mult $3,$2 mflo $2 sw $2,32($fp) lw $5,32($fp) lw $2,%got($LC6)($28) nop addiu $4,$2,%lo($LC6) lw $2,%call16(printf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,printf 1: jalr $25 nop lw $28,16($fp) lw $3,52($fp) lw $2,60($fp) nop bne $2,$0,1f div $0,$3,$2 break 7 1: mfhi $2 mflo $2 sw $2,36($fp) lw $5,36($fp) lw $2,%got($LC7)($28) nop addiu $4,$2,%lo($LC7) lw $2,%call16(printf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,printf 1: jalr $25 nop lw $28,16($fp) lw $3,60($fp) lw $2,56($fp) nop bne $2,$0,1f div $0,$3,$2 break 7 1: mfhi $2 sw $2,40($fp) lw $5,40($fp) lw $2,%got($LC8)($28) nop addiu $4,$2,%lo($LC8) lw $2,%call16(printf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,printf 1: jalr $25 nop lw $28,16($fp) lw $2,52($fp) lw $4,48($fp) li $3,3 # 0x3 bne $3,$0,1f div $0,$4,$3 break 7 1: mfhi $3 move $4,$3 lw $3,60($fp) nop addu $3,$4,$3 sll $4,$3,1 lw $3,56($fp) nop bne $3,$0,1f div $0,$4,$3 break 7 1: mfhi $3 mflo $3 subu $2,$2,$3 sw $2,44($fp) lw $5,44($fp) lw $2,%got($LC9)($28) nop addiu $4,$2,%lo($LC9) 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,68($sp) lw $fp,64($sp) addiu $sp,$sp,72 j $31 nop .set macro .set reorder .end main .size main, .-main .ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote