Write a MIPS assembly language program that reads a customer\'s current and prev
ID: 3890446 • Letter: W
Question
Write a MIPS assembly language program that reads a customer's current and previous meter readings of electricity and a month to compute its electricity bill. If a customer spent 0 or less (technically this should not happen, though) KWH (kilowatt-hours) that is computed by current meter reading - previous meter reading, then the program should print out "There is no bill to pay. ". If a customer spent less than or equals to 300 KWH in a month, then the payment should be 20 dollars. If a customer spent more than 300 KWH in a month of May, June, July, August, or September, then the payment is computed by: payment = 20 + (used KWH - 300) / 15; If a customer spent more than 300 KWH in any other month, then the payment is compute by: payment = 20 + (used KWH - 300) /20; Then if the payment is greater than 0, it should print out the payment amount, along with its used KWH
The following shows how it looks like in a C program:
Explanation / Answer
.file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .rdata .align 2 $LC0: .ascii "Please enter the current electricity meter reading: " .align 2 $LC1: .ascii "%d " .align 2 $LC2: .ascii "Please enter the previous electricity meter reading: " .align 2 $LC3: .ascii "Please enter a month to compute their electricity bill, " .align 2 $LC4: .ascii "Use an integer between 1 and 12 (1 for January, etc.): " .align 2 $LC5: .ascii "There is no bill to pay. " .align 2 $LC6: .ascii "Your total payment for this month: %d dollar(s) for %d K" .ascii "WH
" .text .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $fp,56,$31 # vars= 24, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-56 sw $31,52($sp) sw $fp,48($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,32 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,36 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) nop lw $2,%got($LC4)($28) nop addiu $4,$2,%lo($LC4) 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,40 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,32($fp) lw $2,36($fp) nop subu $2,$3,$2 sw $2,28($fp) lw $2,28($fp) nop bgtz $2,$L2 nop lw $2,%got($LC5)($28) nop addiu $4,$2,%lo($LC5) lw $2,%call16(puts)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,puts 1: jalr $25 nop lw $28,16($fp) b $L3 nop $L2: lw $2,28($fp) nop slt $2,$2,301 beq $2,$0,$L4 nop li $2,20 # 0x14 sw $2,24($fp) b $L5 nop $L4: lw $2,28($fp) nop slt $2,$2,301 bne $2,$0,$L6 nop lw $2,40($fp) nop slt $2,$2,5 bne $2,$0,$L6 nop lw $2,40($fp) nop slt $2,$2,10 beq $2,$0,$L6 nop lw $2,28($fp) nop addiu $3,$2,-300 li $2,15 # 0xf bne $2,$0,1f div $0,$3,$2 break 7 1: mfhi $2 mflo $2 addiu $2,$2,20 sw $2,24($fp) b $L5 nop $L6: lw $2,28($fp) nop addiu $3,$2,-300 li $2,20 # 0x14 bne $2,$0,1f div $0,$3,$2 break 7 1: mfhi $2 mflo $2 addiu $2,$2,20 sw $2,24($fp) $L5: lw $6,28($fp) lw $5,24($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) $L3: move $2,$0 move $sp,$fp lw $31,52($sp) lw $fp,48($sp) addiu $sp,$sp,56 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"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.